DllCompareFunctions

- beta testing -

- send us an email if you have problems using this feature -

 

Name

 

            DllCompareFunctions

 

Type

 

            Read/Write

 

When to use it

 

            Before the optimization is started.

 

Prototype

 

            property DllCompareFunctions: BSTR;

 

Explanations

 

            Specify the name (and the path) of the dll which contains the functions for comparing 2 solutions.

            By writing an optimization function the programmer can customize the component for his particular case.

 

            Because the component does both local and global optimization the dll should contain functions for comparing 2 sheets and for comparing 2 global solutions (made of multiple sheets):

 

            CompareSheets - for comparing 2 sheets.

            CompareGlobalSolutions- for comparing 2 global solutions.

 

            Function CompareSheets has 2 parameters of type TSheet* which are defined in the examples attached to this component.

            Function CompareGlobalSolutions has 2 parameters of type TSheetList* which are defined in the examples attached to this component.

 

 

            The functions must return:

 

-1 if the first parameter (either single sheet or complete solution) is better than the second.

1 if the second sheet is better than the first.

0 if they are equal.

 

Remarks

 

            The function must be implemented in such way that it covers all possible cases of comparing 2 solution. Otherwise the component can crash or can run forever.

 

 

Example

 

Here is a short example on how to implement the dll functions. All required structures are defined below.

 

 

struct TLongPoint{
    long x, y;
};

struct TCut{
    TLongPoint top_left, bottom_right; // coordinates of the corners
    long thick; // thickness
    long level; // level, for multi stage only
    char type; // for multi stage only; virtual (1) or real (0)
    long r; // reserved
};

struct TPiece{
    TLongPoint top_left, bottom_right; // coordinates of the corners
    long width; // size
    long height; // size
    char rotated; // '\1' if rotated compared to the original position, \0' otherwise
    long index; // index as it was given as input
    long e_ID; // external ID
};

struct TWaste{
    TLongPoint top_left, bottom_right; // coordinates of the corners
    long width; // size
    long height; // size
    long r1; // reserved
    long r2; // reserved
    bool r3; // reserved
    long r4, r5, r6, r7; // reserved
    long r8; // reserved
};

class TSheet{
public:
    long Length, Width; // size of the sheet

    long num_parts; // number of demand pieces

    TPiece *pieces; // all pieces placed in the current sheet
    long num_pieces; // number of utilized pieces

    TCut *cuts; // the cuts
    long num_cuts; // number of cuts

    TWaste *wastes; // wastes
    long num_wastes; // number of cuts
};


struct node{
    void* info; // each element here is a TSheet
    node* next;
};

class TSheetList{ // a list of TSheet
public:
    node* head, *tail;
    long count;
};

//---------------------------------------------------------------------------
extern "C" __declspec(dllexport) long CompareSheets(TSheet *a, TSheet *b)
{
    // TO DO: make your own implementation for CompareSheets function

    // here is a simple example for guillotine
    // for nested optimization this example is NOT ok because there are no waste rectangles for it (the num_wastes is 0 in this case).

    // I compute the total waste of each sheet
    // the sheet with the smallest waste is the best ...

    if (b->num_pieces == 0) // b has no pieces placed on it
        if (a->num_pieces == 0) // a has no pieces placed on it
            return 0;
        else
            return -1;
    else
        if (a->num_pieces == 0)
            return 1;


    double waste_a = 0;
    for (int i = 0; i < a->num_wastes; i++)
        waste_a += a->wastes[i].height * a->wastes[i].width;

    double waste_b = 0;
    for (int i = 0; i < b->num_wastes; i++)
        waste_b += b->wastes[i].height * b->wastes[i].width;

    if (waste_a < waste_b)
        return -1;
    else
        if (waste_a > waste_b)
            return 1;
        else
            return 0;
}
//---------------------------------------------------------------------------
extern "C" __declspec(dllexport) long CompareGlobalSolutions(TSheetList *a, TSheetList *b)
{
    // TO DO: make your own implementation for CompareGlobalSolutions function

    // here is a simple example for guillotine.

    // I compute the total waste in each solution
    // the sheet with the smallest total waste is the best ...
    if (b->count == 0) // b has no sheets
        if (a->count == 0) // a has no sheets
            return 0;
        else
            return -1;
    else
        if (a->count == 0)
            return 1;

    double total_waste_a = 0;
    node* ptr = a->head;
    while (ptr != NULL){
        TSheet * curr_sheet = (TSheet *)ptr->info;
        for (int i = 0; i < curr_sheet->num_wastes; i++)
            total_waste_a += curr_sheet->wastes[i].width * curr_sheet->wastes[i].height;
        ptr = ptr->next;
    }

    double total_waste_b = 0;
    ptr = b->head;
    while (ptr != NULL){
        TSheet * curr_sheet = (TSheet *)ptr->info;
        for (int i = 0; i < curr_sheet->num_wastes; i++)
            total_waste_b += curr_sheet->wastes[i].width * curr_sheet->wastes[i].height;
        ptr = ptr->next;
    }

    if (total_waste_a < total_waste_b)
        return -1;
    else
        if (total_waste_a > total_waste_b)
            return 1;
        else
            return 0;
}
//---------------------------------------------------------------------------
 

See also

           

            StartGuillotine, StartNested, StartMultiStages,