Decision Optimization

 View Only
Expand all | Collapse all

CP flowshop

  • 1.  CP flowshop

    Posted Tue December 29, 2020 04:57 AM

    Dears;

    I would appreciate your help regarding the model below. In this model, I am using CP solver to minimise the tardiness .When i run the model i get some results that seems to me incoherent. Can you please tell me what i'm doing wrong.

    Please find the model and data below:

    .mod:

    using CP;

    int nbJobs = ...;
    int nbMchs = ...;
    int nbOps=...;

    range Jobs = 0..nbJobs-1;
    range Mchs = 0..nbMchs-1;
    range ops = 1..nbOps;
    // Mchs is used both to index machines and operation position in job

    tuple Operation {
    int opid;
    string jobid;
    int mch; // Machine, operation id
    float pt; // Processing time
    float st; // setup time
    };

    Operation Ops[j in ops] = ...;

    string duedate[i in Jobs]=...;
    int duedateint[i in Jobs];

    execute
    {
    for(var i in Jobs)
    {
    var temp=new Date(duedate[i]);
    duedateday=Opl.ftoi(Opl.round((temp)/1000/3600/24));
    duedateint[i]=duedateday;
    }
    }

    dvar interval itvs[j in Jobs][o in Mchs] ;
    dvar sequence mchs[m in Mchs] in all(j in Jobs, o in Mchs : Ops[j in ops].mch == m) itvs[j][o];

    execute {
    cp.param.TimeLimit = 600;
    cp.param.RestartFailLimit = 1000;
    cp.param.RelativeOptimalityTolerance = 0;
    cp.param.OptimalityTolerance = 0;
    cp.param.FailLimit = 300000;
    }

    minimize max(j in Jobs) endOf(itvs[j][nbMchs-1]);
    subject to {

    forall (m in Mchs)
    noOverlap(mchs[m]);

    forall (j in Jobs, o in 0..nbMchs-2)
    endBeforeStart(itvs[j][o], itvs[j][o+1]);

    forall (j in Jobs, o in 0..nbMchs-2)
    endOf(itvs[j][o])<=duedateint[j];
    }

    .data:

    nbJobs = 46;
    nbMchs = 19;
    nbOps=218;


    SheetConnection datasheet("Data bro.xlsx");
    Ops from SheetRead (datasheet,"OPS");
    duedate from SheetRead (datasheet,"duedate");



    ------------------------------
    So jana
    ------------------------------


    #DecisionOptimization


  • 2.  RE: CP flowshop

    Posted Tue December 29, 2020 09:56 AM

    Dear Jana,

    Could you please precise what version of CPLEX studio you are using and provide the log that you get when running CP optimizer?

    Thank you in advance,



    ------------------------------
    Renaud Dumeur
    ------------------------------



  • 3.  RE: CP flowshop

    Posted Wed December 30, 2020 03:04 AM

    Dear renaud;
    Iam using CPLEX Studio IDE 12.10.0, i get this message when i run the model :

    This is not a "duedateday" template element, use 'var' to declare local script variables.

    itvs:

    mchs:

    Thank you



    ------------------------------
    So jana
    ------------------------------



  • 4.  RE: CP flowshop

    Posted Wed January 06, 2021 08:53 AM
    Edited by System Fri January 20, 2023 04:19 PM
    Hi, could you explain what you mean by "i get some results that seems to me incoherent" ?
    I noticed 3 strange things in the model:

    1) The interval variables representing the operations are defined without specifying any length (duration) so the engine consider the length is unconstrained (domain is [0,+oo)) and thus for instance it can be 0 for all operations:

    dvar interval itvs[j in Jobs][o in Mchs] ;

    2) You say that you minimise the tardiness but the model minimizes the makespan. 

    3) If you want to post constraints that the tardiness (delay of last operation of the jobs j compared to duedateint[j]) should be 0, I think your constraint is wrong. Instead of:

    forall (j in Jobs, o in 0..nbMchs-2)
      endOf(itvs[j][o]) <= duedateint[j];
    }

    you should post something like:

    endOf(itvs[j][nbMchs-1]) <= duedateint[j];

    And if you really want to minimize the total tardiness, you should remove these constraints and do something like:

    minimize sum(j in Jobs) maxl(0, endOf(itvs[j][nbMchs-1])-duedateint[j]);



    ------------------------------
    Philippe Laborie
    ------------------------------



  • 5.  RE: CP flowshop

    Posted Wed January 06, 2021 09:55 AM
    Hello,

    In addition to these modeling tips from my colleague Philippe, I would like to draw your attention to possible problems reading dates in excel.
    The constructor of "Date" requires a string which follows a strict format "MM/DD/YYYY".
    The string returned by SheetRead depends on your local settings.
    You may check your "Regional format data", the "Short date" format should match the format required by the constructor of Date.

    I hope this helps.

    ------------------------------
    Christiane Bracchi
    ------------------------------



  • 6.  RE: CP flowshop

    Posted Wed January 06, 2021 03:42 PM

    Hi Philippe and Christiane, 

    Thank you for your answer;
    Iam new to cplex , i don't master it, so i really appereciate your help .
    i made the requested changes but when i run the model it doesn't give me any result even after almost 2 hours!
    If you have any idea how to make it solvable, I will really appreciate that!

    Best regards



    ------------------------------
    So jana
    ------------------------------



  • 7.  RE: CP flowshop

    Posted Thu January 07, 2021 11:19 AM
    You have to be more precise. What do you mean by "it doesn't give me any result even after almost 2 hours!". What happens? Do you have a log of the search or some error messages to share with us?

    There is clearly a problem with this line of your code:

    dvar interval itvs[j in Jobs][o in Mchs] size (Ops[j].pt+Ops[j].st);

    Because on the left side (j in Jobs) j is an index of the jobs (in 0..nbJobs-1) whereas on the right side it is used to index Ops which is indexed on 1..nbOps. So Ops[0] does not exist.

    As your 
    flow shop problem is not rectangular (the number of operations is not the same for each jobs), you cannot use a 2-D array for operations itvs, you need to index them with a tuple set.

    There is also some potential ambiguity in your data because the table that gives the due date of jobs is indexed by numbers (job 1, job 2, ...) whereas in the first table, jobs are identified by ids (OFB2001618, OFB2001619, ...) ...

    I tried to fixed manually these problems in the two attached files (the data file is not in Excel but directly as an OPL data file).


    ------------------------------
    Philippe Laborie
    ------------------------------



  • 8.  RE: CP flowshop

    Posted Thu January 07, 2021 12:12 PM
    Hello,

    In addition to Philippe's comments I would like to mention that we had to preprocess your data a little (integers vs floats).
    In case you need to upload again some material of your project, it would be faster for us to help you if you provide a .dat only, without any reference to excel by exporting your data.
    You can generate it by
         oplrun -de forUpload.dat yourModel.mod yourModel.dat
    then you'll be able to try
        oplrun yourModel.mod forUpload.dat
    which should have the same behaviour than using your .dat which refers to excel, and upload yourModel.mod and forUpload.dat.

    Regards,



    ------------------------------
    Christiane Bracchi
    ------------------------------



  • 9.  RE: CP flowshop

    Posted Fri January 08, 2021 05:22 AM

    Hello Christiane;

    Thank you , but i didn't figure out how to convert my data (excel) to a.data automatically!

    Best regards 



    ------------------------------
    So jana
    ------------------------------



  • 10.  RE: CP flowshop

    Posted Fri January 08, 2021 05:31 AM
    Hello,
    Did you try
        oplrun -de forUpload.dat yourModel.mod yourModel.dat
    ?

    ------------------------------
    Christiane Bracchi
    ------------------------------



  • 11.  RE: CP flowshop

    Posted Thu January 14, 2021 03:42 AM

    Hello christiane;

    Should i run this code in the command prompt ?
     oplrun -de forUpload.dat "myModel.mod" "myModel.dat"

    Thank you



    ------------------------------
    So jana
    ------------------------------



  • 12.  RE: CP flowshop

    Posted Thu January 14, 2021 04:30 AM

    Hello,

    Yes
         oplrun -de forUpload.dat yourModel.mod yourModel.dat
    has to be called from a command prompt.
    The same thing can be done from the IDE:
         Run > Export external data...

    Regards,



    ------------------------------
    Christiane Bracchi
    ------------------------------



  • 13.  RE: CP flowshop

    Posted Thu January 14, 2021 05:04 AM
    I tried the code from the command prompt and the IDE but it replies file not found, even i make sure that i write the file name correctly.

    Regards

    ------------------------------
    So jana
    ------------------------------



  • 14.  RE: CP flowshop

    Posted Thu January 14, 2021 09:13 AM
    Good morning,

    You can create a simple batch file and run it (double click). The batch file could be saved as MyModel.bat.
    Below is an example of a batch file I just tested. You need to define the path to your .mod and .dat files.

    @setlocal
    @echo off
    oplrun  "C:\opl\Test\Test.mod" "C:\opl\Test\Test.dat" >> C:\opl\Test\Test.log
     if "%shouldexit%" == "yes" exit
    @endlocal


    ------------------------------
    Nourredine Hail
    ------------------------------



  • 15.  RE: CP flowshop

    Posted Fri January 08, 2021 05:16 AM

    Thank you Philippe for your explanations now i absorb it .I have to ask about two other other things:
    1.Can i use a string for mchs in the tuple Operation. as in the Excel file, if yes how can i use it in dvar sequence mchs[m in Mchs] in all(o in Operations : o.mch == m) itvs[o].
    2.I am also wondering how i can express the result in this way :
    (start date and start time ) (completion date at completion time) (MM/DD/YYYY at HH:SS) , knowing that the horizon start is (06/07/2020)



    ------------------------------
    So jana
    ------------------------------



  • 16.  RE: CP flowshop

    Posted Fri January 08, 2021 06:10 AM
    1. Yes, nothing changes in the model except that Machines will be declared as string:

    tuple Operation {
    key int opid;
    key string jobid;
    string mch; // Machine, operation id
    int pt; // Processing time
    int st; // Setup time
    };

    ...

    {string} Mchs = { o.mch | o in Operations };

    2. You should have a look at the documentation of dates in OPL: here. If you decide to use time value 0 as start date (06/07/2020) in your model, don't forget to remove 06/07/2020 from the due dates when computing the "model" due dates. I suggest you have two functions for date_time / model_time_unit translation : one to translate date_time to model_time_unit and the other for the reverse translation.

    ------------------------------
    Philippe Laborie
    ------------------------------



  • 17.  RE: CP flowshop

    Posted Fri January 08, 2021 01:57 PM

    I tried this to translate dates, but i get this message when i run the model :'

    Script execution error: No OPL function "startOf (dvar interval [Operations])" 23>] ".


    To translate Date time to model time:

    string horizonstart="05/11/2020";
    execute {
    for(var d in DueDates) {
    var hs=new Date(horizonstart);
    var temp=new Date(d.duedate);
    var duedateday=Opl.ftoi(Opl.round((temp-hs)/1000/3600/24));
    duedateint[d.jobid]=duedateday;
    }

    model time----> date time

    execute
    {
    var hs=new Date(horizonstart);
    var startItvs=hs+Opl.startOf(itvs)*1000*24*3600;
    writeln("The activity should start at ",new Date(startItvs));
    }

    Can you please check what iam doing wrong . 

    Best regards



    ------------------------------
    So jana
    ------------------------------



  • 18.  RE: CP flowshop

    Posted Sun January 10, 2021 09:42 AM
    Hello
    This API is only available in model, not in Opl Script. Use directly itvs.start instead
    You can have a look at the examples provided in the distribution , and also the documentation
    David

    ------------------------------
    David Gravot
    ------------------------------



  • 19.  RE: CP flowshop

    Posted Thu January 14, 2021 03:38 AM
    Edited by System Fri January 20, 2023 04:14 PM
    Hello David;

    I tried this, but i don't know what iam doing wrong:
    execute
    {
    var hs=new Date(horizonstart);
    var startItvs=hs+Opl.itvs.start*1000*24*3600;
    writeln("The activity should start at ",new Date(startItvs));
    }
    I get this when i run the model:
    The activity should start at -2147483645/-2147483648/-2147483648 ...

    the result i want to get is:The activity should start a tmm/dd/yyyy hh:mm

    Thank you

    ------------------------------
    So jana
    ------------------------------



  • 20.  RE: CP flowshop

    Posted Thu January 14, 2021 04:20 AM
    Hello,

    hard to answer without knowing the input values. I suggest to print them (just for debugging) so we can see what happens:

    execute
    {
    writeln(horizonstart);
    var hs=new Date(horizonstart);
    writeln(hs);
    writeln(Opl.itvs.start);
    var startItvs=hs+Opl.itvs.start*1000*24*3600;
    writeln("The activity should start at ",new Date(startItvs));
    }

    You can find documentation for Date in the script here: https://www.ibm.com/support/knowledgecenter/cs/SSSA5P_20.1.0/ilog.odms.ide.help/OPL_Studio/opllangref/topics/opl_langref_script_values_dates.html

    In particular Date constructor takes number of milliseconds since January 1, 1970. Operator + should also use number of milliseconds, the code looks like counting number of days though (1000*24*3600). So maybe it can be enough to remove "*1000*24*3600".

    Regards, Petr


    ------------------------------
    Petr Vilím
    IBM
    ------------------------------



  • 21.  RE: CP flowshop

    Posted Thu January 14, 2021 04:34 AM

    Hi peter;

    Here are my .mod and .dat file so you can con see what happens

    Best regards



    ------------------------------
    So jana
    ------------------------------



  • 22.  RE: CP flowshop

    Posted Tue January 19, 2021 03:44 AM
    Hello,

    it seems the code should be:

    execute
    {
    var hs=new Date(horizonstart);
    for (var o in Operations)
      writeln("Operation ", o, " starts at ", new Date(hs + itvs[o].start*1000*24*3600));
    }
    ​


    This code assumes that duration is given in days.

    Regards, Petr

    ------------------------------
    Petr Vilím
    IBM
    ------------------------------



  • 23.  RE: CP flowshop

    Posted Wed January 20, 2021 02:42 AM
    Edited by System Fri January 20, 2023 04:16 PM

    Hi petr;

    Thank you for you help
    this code returns this solution, which seems to be incoherent for me , because there are some operations (ex: op 11 and 13 that have a start date in 2022 and 2021 while the deadline was in 2020 ) also the start time in the solution is 00:00 or 23:00 while i need to express the duration in this format month, day, year  hours :minutes 




    ------------------------------
    So jana
    ------------------------------