Decision Optimization

 View Only
  • 1.  Constraint Optimization OPL

    Posted Thu March 14, 2024 08:37 AM

    I would like to extract my interval and schedule solution from the ILOG constraint programming solver into a text or csv file. I also want to write the run time of the model to a text or csv file. Any suggestions on how to do this?



    ------------------------------
    Richlove Frimpong
    ------------------------------


  • 2.  RE: Constraint Optimization OPL

    Posted Fri March 15, 2024 05:55 AM

    Hi

    from scripting you can write into a csv file as can be seen at https://github.com/AlexFleischerParis/howtowithopl/blob/master/exporttocsv.mod

    execute
        {
        // turn an OPL tupleset into a csv file
        function turnTuplesetIntoCSV(tupleSet,csvFileName)
        {
        var f=new IloOplOutputFile(csvFileName);
    
        var quote="\"";
        var nextline="\\\n";
    
        var nbFields=tupleSet.getNFields();
        for(var j=0;j<nbFields;j++) f.write(tupleSet.getFieldName(j),";");
        f.writeln();
        for(var i in tupleSet)
        {
    
         
    
        for(var j=0;j<nbFields;j++)
        {
    
        var value=i[tupleSet.getFieldName(j)];
        if (typeof(value)=="string") f.write(quote);
        f.write(value);
        if (typeof(value)=="string") f.write(quote);
        f.write(";");
    
        }
        f.writeln();
        }
        f.close();
        }
        }
    
    
        tuple t
        {
        string firstname;
        int number;
        }
    
        {t} s={<"Nicolas",2>,<"Alexander",3>};
    
        execute
        {
        turnTuplesetIntoCSV(s,"export.csv");
        }

    So you can first turn your intervals into a tuple set and then your tuple set into a csv file

    Likewise you can write into a text file any statistics you compute in OPL



    ------------------------------
    [Alex] [Fleischer]
    [Data and AI Technical Sales]
    [IBM]
    ------------------------------