Hi,
// --------------------------------------------------------------------------
// Licensed Materials - Property of IBM
//
// 5725-A06 5725-A29 5724-Y48 5724-Y49 5724-Y54 5724-Y55
// Copyright IBM Corporation 1998, 2013. All Rights Reserved.
//
// Note to U.S. Government Users Restricted Rights:
// Use, duplication or disclosure restricted by GSA ADP Schedule
// Contract with IBM Corp.
// --------------------------------------------------------------------------
// The scalable warehouse example has been artificially increased in size
// so that the search is long enough for you to have time to interrupt it and look at feasible solutions.
// The resulting size is greater than the size allowed in trial mode.
// If you want to run this example, you need a commercial edition of CPLEX Studio to run this example.
// If you are a student or teacher, you can also get a full version through the IBM Academic Initiative.
//int n=...;
//int nbthreads=...;
int Fixed = 40;
int NbWarehouses = 40;
int NbStores = 80;
assert( NbStores > NbWarehouses );
range Warehouses = 1..NbWarehouses;
range Stores = 1..NbStores;
int Capacity[w in Warehouses] =
NbStores div NbWarehouses +
w % ( NbStores div NbWarehouses );
int SupplyCost[s in Stores][w in Warehouses] =
1 + ( ( s + 10 * w ) % 100 );
dvar int Open[Warehouses] in 0..1;
dvar float Supply[Stores][Warehouses] in 0..1;
dexpr int TotalFixedCost = sum( w in Warehouses ) Fixed * Open[w];
dexpr float TotalSupplyCost = sum( w in Warehouses, s in Stores ) SupplyCost[s][w] * Supply[s][w];
//minimize TotalFixedCost + TotalSupplyCost;
dvar float obj;
minimize obj;
subject to {
ctObj:obj==TotalFixedCost + TotalSupplyCost;
forall( s in Stores )
ctStoreHasOneWarehouse:
sum( w in Warehouses )
Supply[s][w] == 1;
forall( w in Warehouses )
ctOpen:
sum( s in Stores )
Supply[s][w] <= Open[w] * Capacity[w];
}
execute
{
writeln("Open=",Open);
}
main
{
thisOplModel.generate();
var o=new IloOplOutputFile("log.txt")
cplex.intsollim=1;
for(var i=1;i<=10;i++)
{
cplex.solve();
thisOplModel.postProcess();
o.writeln("sol ",i);
o.writeln("getBestObjValue = ",cplex.getBestObjValue());
o.writeln("getObjValue = ",cplex.getObjValue());
o.writeln("Open = ",thisOplModel.Open);
o.writeln();
}
o.close();
}
generates log.txt
sol 1
getBestObjValue = 1796.666666667
getObjValue = 1870
Open = [1 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1
1 1 1]
sol 2
getBestObjValue = 1796.666666667
getObjValue = 1820
Open = [0 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1
1 1 1]
sol 3
getBestObjValue = 1820
getObjValue = 1820
Open = [0 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1
1 1 1]
sol 4
getBestObjValue = 1820
getObjValue = 1820
Open = [0 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1
1 1 1]
sol 5
getBestObjValue = 1820
getObjValue = 1820
Open = [0 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1
1 1 1]
sol 6
getBestObjValue = 1820
getObjValue = 1820
Open = [0 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1
1 1 1]
sol 7
getBestObjValue = 1820
getObjValue = 1820
Open = [0 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1
1 1 1]
sol 8
getBestObjValue = 1820
getObjValue = 1820
Open = [0 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1
1 1 1]
sol 9
getBestObjValue = 1820
getObjValue = 1820
Open = [0 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1
1 1 1]
sol 10
getBestObjValue = 1820
getObjValue = 1820
Open = [0 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1
1 1 1]
regards
https://www.linkedin.com/pulse/puzzles-having-fun-useful-mathematics-alex-fleischer/
#DecisionOptimization#OPLusingCPLEXOptimizer