Hi,
see example in OPL
https://community.ibm.com/community/user/datascience/communities/community-home/digestviewer/viewthread?MessageKey=2e7e9b61-1183-48c9-be12-2dfd33e2ef09&CommunityKey=ab7de0fd-6f43-47a9-8261-33578a231bb7&tab=digestviewer#bm2e7e9b61-1183-48c9-be12-2dfd33e2ef09With doopl you can do the same
if you write warmstartcposchedulingdoopl
using CP;
tuple t
{
int v;
}
{t} s=...;
{int} mySet={ i.v | i in s};
range r = 1..10;
dvar interval x[r] size 1;
dvar interval y[r] size 1;
// The following array of values (defined as data) will be used as
// a starting solution to warm-start the CP Optimizer search.
int values[i in r] = (i in mySet)? 10 : 0;
minimize sum( i in r ) startOf(x[i]) + sum( j in r ) startOf(y[j]);
subject to
{
ctSum: sum( i in r ) startOf(x[i]) >= 10;
forall( j in r ) ctEqual: startOf(y[j]) == j;
}
execute
{
for(i in r) write(Opl.startOf(x[i])," ");
writeln();
}
tuple t2
{
int a;
int b;
}
{t2} result={<i,startOf(x[i])> | i in r};
execute
{
result;
}
main
{
thisOplModel.generate();
var sol=new IloOplCPSolution();
for(var i=1;i<=10;i++) sol.setStart(thisOplModel.x[i],thisOplModel.values[i]);
cp.solve();
thisOplModel.postProcess();
cp.setStartingPoint(sol);
cp.solve();
thisOplModel.postProcess();
} then you can write the python file
from doopl.factory import *
# Create an OPL model from a .mod file
with create_opl_model(model="warmstartcposchedulingdoopl.mod") as opl:
# tuple can be a list of tuples, a pandas dataframe...
s=[(5,),]
opl.set_input("s",s )
# Generate the problem and solve it.
opl.run()
# Get the names of post processing tables
print("Table names are: "+ str(opl.output_table_names))
# Get all the post processing tables as dataframes.
for name, table in iteritems(opl.report):
print("Table : " + name)
for t in table.itertuples(index=False):
print(t)which will give you
Table names are: ['result']
Table : result
Pandas(a=1, b=0)
Pandas(a=2, b=0)
Pandas(a=3, b=0)
Pandas(a=4, b=0)
Pandas(a=5, b=10)
Pandas(a=6, b=0)
Pandas(a=7, b=0)
Pandas(a=8, b=0)
Pandas(a=9, b=0)
Pandas(a=10, b=0)
regards
------------------------------
ALEX FLEISCHER
------------------------------