【问题标题】:Creating subset in CPLEX在 CPLEX 中创建子集
【发布时间】:2022-12-03 01:18:47
【问题描述】:

我正在研究与具体交付问题相关的公式。我在 CPLEX 中实现了公式,但在构造方面遇到了一些问题 集合子集的离子。例如,我需要构造一组图的人工节点的所有子集。我所做的是:




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;


【问题讨论】:

    标签: cplex cdp


    【解决方案1】:

    示例中集合的所有子集 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);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-30
      • 1970-01-01
      • 1970-01-01
      • 2017-07-31
      • 1970-01-01
      • 1970-01-01
      • 2017-01-25
      • 2012-10-09
      相关资源
      最近更新 更多