Decision Optimization

Expand all | Collapse all

CP flowshop

  • 1.  CP flowshop

    Posted 17 days ago
      |   view attached

    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
    ------------------------------

    Attachment(s)

    xlsx
    Data bro.xlsx   20 KB 1 version


  • 2.  RE: CP flowshop

    Posted 17 days ago

    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 16 days ago

    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 9 days ago
    Edited by Philippe Laborie 9 days ago
    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 9 days ago
    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 9 days ago

    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
    ------------------------------

    Attachment(s)

    mod
    1 Bro CP vf.mod   1 KB 1 version
    dat
    1 Bro CP vf.dat   346 B 1 version
    xlsx
    Data bro int.xlsx   20 KB 1 version


  • 7.  RE: CP flowshop

    Posted 8 days ago
    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
    ------------------------------

    Attachment(s)

    dat
    flowshop.dat   8 KB 1 version
    mod
    flowshop.mod   1 KB 1 version


  • 8.  RE: CP flowshop

    Posted 8 days ago
    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 7 days ago

    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 7 days ago
    Hello,
    Did you try
        oplrun -de forUpload.dat yourModel.mod yourModel.dat
    ?

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



  • 11.  RE: CP flowshop

    Posted yesterday

    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 yesterday

    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 yesterday
    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 yesterday
    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 7 days ago
      |   view attached

    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
    ------------------------------

    Attachment(s)

    xlsx
    Data vf.xlsx   16 KB 1 version


  • 16.  RE: CP flowshop

    Posted 7 days ago
    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 7 days ago

    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 5 days ago
    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 yesterday
    Edited by So jana yesterday
    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 yesterday
    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 yesterday

    Hi peter;

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

    Best regards



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

    Attachment(s)

    dat
    1 bro ph cp.dat   8 KB 1 version
    mod
    1 bro ph cp.mod   1 KB 1 version