Creating subset in CPLEX

103 Views Asked by At

I'm working on a formulation related to the Concrete Delivery Problem. I implement the formulation in CPLEX but face some problems with the construct ion of subset of the sets. For example, I need to construct a set of all subsets of artificial nodes of the graph. What I do is the following:




int st=...;
{int} StartingLocation = asSet(1..st);
int ft=...;
{int} FinishingLocation = asSet(1..ft);
int m2=1; // amount of customer type 2
int m4=1; // amount of customer type 4
{int} Customer2_NOTdefinedCustomers_NONSingleSource = asSet(1..m2);
{int} Customer4_DefinedCustomers_NONsingleSource = asSet(m2..m4+m2);
// Number of actual Customer nodes
{int} Customers = Customer2_NOTdefinedCustomers_NONSingleSource union Customer4_DefinedCustomers_NONsingleSource ;
float Deadline[Customers]= ...; // deadline
float demand[Customers]= ...;
int TimeLag[Customers] = ...;
float DefaultLoadSize = ...;
float LoadPerTrip = ... ;
int definedORnot [Customers] = ...;
int NofArtificialCustomers = 0;
int maxNumber_ofDeliveries[x in Customers];
execute {
for( var l in Customers){
if (definedORnot == 1)
maxNumber_ofDeliveries[l] = Opl.ftoi(Opl.ceil(DefaultLoadSize/demand[l]));
else maxNumber_ofDeliveries[l] = Opl.ftoi(Opl.ceil(demand[l]/LoadPerTrip));
// calculating the number of artificial customer nodes
NofArtificialCustomers = NofArtificialCustomers + maxNumber_ofDeliveries[l];
}
}
int NoCustomers = card(Customers); // the number of Actual nodes for customers
{int} SetofArtCustomerNodes[i in 1..NoCustomers] = asSet(1..maxNumber_ofDeliveries[i]);
// CREATING THE ARTIFICIAL CUSTOMER NODES
tuple artificialnodes {int i ; int j;}
// B: the set of artificial customer nodes
{artificialnodes} Setof_ArtificialCustomers = {<i,j> | i in Customers, j in SetofArtCustomerNodes[i in Customers]};
int d = ...;
{int} Depots = asSet(m4+m2..d+m4+m2);
{int} SetofArtDepotNodes = asSet(1..NofArtificialCustomers);
// CREATING THE ARTIFICIAL DEPOT NODES
{artificialnodes} Setof_ArtificialDepots = {<i,j> | i in Depots, j in SetofArtDepotNodes};
int NoV = ...; // amount of vehicles
{int} Vehicles = asSet(1..NoV); // set of vehicles
// CREATING THE ARTIFICIAL STARTING LOCATION NODES
{artificialnodes} Setof_StartingLocations = {<i,j> | i in Vehicles, j in Customers: j==1};
// CREATING THE ARTIFICIAL FINISHING LOCATION NODES
{artificialnodes} Setof_FinishingLocations = {<i,j> | i in Vehicles, j in Customers: j==1};
{artificialnodes} N0 = Setof_StartingLocations union Setof_FinishingLocations union Setof_ArtificialDepots union Setof_ArtificialCustomers;


1

There are 1 best solutions below

0
On

All subsets of a set in example https://github.com/AlexFleischerParis/howtowithopl/blob/master/powerset.mod

{string} s={"A","B","C","D"};
range r=1.. ftoi(pow(2,card(s)));
{string} s2 [k in r] = {i | i in s: ((k div (ftoi(pow(2,(ord(s,i))))) mod 2) == 1)};

execute
{
 writeln(s2);
}

With your artificial nodes you can write

tuple artificialnodes {int i ; int j;}

{artificialnodes} nodes={<1,2>,<3,4>,<5,6>,<1,4>};


range r=1.. ftoi(pow(2,card(nodes)));
{artificialnodes} s2 [k in r] = {i | i in nodes: ((k div (ftoi(pow(2,(ord(nodes,i))))) mod 2) == 1)};

execute
{
 writeln(s2);
}

which gives

[{<1 2>} {<3 4>} {<1 2> <3 4>} {<5 6>} {<1 2> <5 6>} {<3 4>
         <5 6>} {<1 2> <3 4> <5 6>} {<1 4>} {<1 2> <1 4>} {
        <3 4> <1 4>} {<1 2> <3 4> <1 4>} {<5 6> <1 4>} {<1 2>
         <5 6> <1 4>} {<3 4> <5 6> <1 4>} {<1 2> <3 4> <5 6>
         <1 4>} {}]