为什么我的解决方案对 sum(n in order) 的值与 sum(n in order:(n-1) in order) 的值相同

Why is does my solution give the same value for sum(n in order) as for sum(n in order:(n-1) in order)

我正在进行合并 model,您可以在其中查看哪些订单已合并,哪些不是基于其假设的数量。但是,我的代码不适用于所有订单组合...这是我的 .mod 文件:

//GENERAL PARAMETERS
 int nr_trucks = ...;
 
    //Sets
 {int} origin_terminal = ...;
 {int} gateway_terminal = ...;
 {int} destination_terminal = ...;
 
 {int} order = ...;
 {int} cons_truck = ...;
 
 int capacity_cons_truck[cons_truck] = ...;
 
    //Ranges
 range truck = 1..nr_trucks;
 
 //ORDER PARAMETERS
 int volume[order] = ...;
 int non_cons_truck[order] = ...;
 
 //NETWORK PARAMETERS
 int fixed_cost_OTG[origin_terminal, gateway_terminal] = ...;
 int fixed_cost_GTD[gateway_terminal, destination_terminal] = ...;
 
 //DECISION VARIABLE
 dvar int+ x_OTG[origin_terminal, gateway_terminal, truck, order] in 0..1;
 dvar int+ x_GTD1[gateway_terminal, destination_terminal, truck, order] in 0..1;
 dvar int+ x_GTD2[gateway_terminal, destination_terminal, cons_truck, order] in 0..1;
 
 //OUTPUT VARIABLES
 dvar int+ y[gateway_terminal, truck, cons_truck, order] in 0..1;
 dvar float exp_fixed_cost_1[origin_terminal, gateway_terminal, truck, order];
 dvar float exp_fixed_cost_2[gateway_terminal, destination_terminal, truck, order];
 dvar float+ exp_fixed_cost_3[gateway_terminal, destination_terminal, cons_truck];
 dvar int+ A[cons_truck];
 dvar int+ B[cons_truck];

 //PARAMETERS TO WRITE OUTPUT TO EXCEL
 tuple tuple_x
 {
   int terminal;
   int terminal2;
   int truck;
   int order;
   int value;
 };
 
 tuple tuple_y
 {
   int terminal;
   int truck;
   int cons_truck;
   int order;
   int value;
 };
 
 tuple tuple_cost_1_2
 {
   int terminal;
   int terminal2;
   int truck;
   int order;
   float value;
 };
 
  tuple tuple_cost_3
 {
   int terminal;
   int terminal2;
   int truck;
   float value;
 };
 
 
 //MODEL
 minimize sum(n in order) exp_fixed_cost_1[1,1,non_cons_truck[n],n]
        + sum(n in order) exp_fixed_cost_2[1,1,non_cons_truck[n],n]
        + sum(h in cons_truck) exp_fixed_cost_3[1,1,h];
        
 subject to
 {
  //FLOW CONSTRAINTS
  forall(n in order) x_OTG[1,1,non_cons_truck[n],n] == 1; //(2)
  
  forall(n in order) x_OTG[1,1,non_cons_truck[n],n] ==  x_GTD1[1,1,non_cons_truck[n],n] + sum(h in cons_truck) x_GTD2[1,1,h,n]; //(3)
  
  //forall(n in order, h in cons_truck) x_OTG[1,1,non_cons_truck[n],n] + x_GTD2[1,1,h,n] <= 1 + y[1,non_cons_truck[n],h,n]; //(4a) minder strikt?
  forall(h in cons_truck, n in order) y[1,non_cons_truck[n],h,n] == x_GTD2[1,1,h,n]; //(4a)
  forall(h in cons_truck) sum(n in order) y[1,non_cons_truck[n],h,n]*volume[n] <= capacity_cons_truck[h]; //(4b) 
  forall(h in cons_truck) sum(n in order) y[1,non_cons_truck[n],h,n] != 1; //(4c) only more than 2 order can be put on a consolidated truck
  
  forall(n in order) sum(h in cons_truck) y[1,non_cons_truck[n],h,n] <= 1; //(5a) order cannot be split over multiple trucks
  forall(n in order) sum(h in cons_truck) x_GTD2[1,1,h,n] <= 1; //(5b)
  
  forall(h in cons_truck) sum(n in order) y[1,non_cons_truck[n],h,n] == A[h]; //number of consolidated orders in truck h
  forall(h in cons_truck) sum(n in order: (n-1) in order) y[1,non_cons_truck[n],h,n] == B[h]; //all but one consolidated orders in h
    
  
  //EXPECTED FIXED COSTS
  forall(n in order) exp_fixed_cost_1[1,1,non_cons_truck[n],n] >= fixed_cost_OTG[1,1]*x_OTG[1,1,non_cons_truck[n],n]; //(6a)
  forall(n in order) exp_fixed_cost_2[1,1,non_cons_truck[n],n] >= fixed_cost_GTD[1,1]*x_GTD1[1,1,non_cons_truck[n],n]; //(6b)
  forall(h in cons_truck) exp_fixed_cost_3[1,1,h] >= sum(n in order) x_GTD2[1,1,h,n]*fixed_cost_GTD[1,1] - sum(n in order: (n-1) in order) y[1,non_cons_truck[n],h,n]*fixed_cost_GTD[1,1] ; //(6c) 
    
  forall(n in order) exp_fixed_cost_1[1,1,non_cons_truck[n],n] >= 0;
  forall(n in order) exp_fixed_cost_2[1,1,non_cons_truck[n],n] >= 0;
  forall(n in order, h in cons_truck) exp_fixed_cost_3[1,1,h] >= 0;
 }
 
 //OUTPUT TO EXCEL
 {tuple_x} output_x_OTG = {<i,j,g,n,x_OTG[i,j,g,n]> | i in origin_terminal, j in gateway_terminal, g in truck, n in order};
 {tuple_x} output_xGTD1 = {<i,j,g,n,x_GTD1[i,j,g,n]> | i in gateway_terminal, j in destination_terminal, g in truck, n in order};
 {tuple_x} output_xGTD2 = {<i,j,h,n,x_GTD2[i,j,h,n]> | i in gateway_terminal, j in destination_terminal, h in cons_truck, n in order};
 
 {tuple_y} output_y = {<i,g,h,n,y[i,g,h,n]> | i in gateway_terminal, g in truck, h in cons_truck, n in order};
 
 {tuple_cost_1_2} output_exp_fixed_cost_1 = {<i,j,g,n,exp_fixed_cost_1[i,j,g,n]> | i in origin_terminal, j in gateway_terminal, g in truck, n in order};
 {tuple_cost_1_2} output_exp_fixed_cost_2 = {<i,j,g,n,exp_fixed_cost_2[i,j,g,n]> | i in gateway_terminal, j in destination_terminal, g in truck, n in order};
 {tuple_cost_3} output_exp_fixed_cost_3 = {<i,j,h,exp_fixed_cost_3[i,j,h]> | i in gateway_terminal, j in destination_terminal, h in cons_truck};
 

这是我的 .dat 文件:

SheetConnection excel("One_to_one_no_leadtime.xlsx");

 //GENERAL PARAMETERS
 //nr_orders = 3;
 nr_trucks = 3;
 
 origin_terminal = {1};
 gateway_terminal = {1};
 destination_terminal = {1};
 
 order = {1,2,3};
 cons_truck = {1,2,3};
 
 //ORDER PARAMETERS
 volume = [40,70,20];
 non_cons_truck = [1,2,3];
 capacity_cons_truck = [100,100,100];
 
 //NETWORK PARAMETERS
 fixed_cost_OTG = [[75]];
 fixed_cost_GTD = [[75]];
 
 //OUTPUT WEGSCHRIJVEN
 output_x_OTG to SheetWrite(excel,"'output'!A3:E1100");
 output_xGTD1 to SheetWrite(excel,"'output'!G3:K1100");
 output_xGTD2 to SheetWrite(excel,"'output'!M3:Q1200");
 
 output_y to SheetWrite(excel,"'output'!S3:W1000");
 
 output_exp_fixed_cost_1 to SheetWrite(excel,"'cost'!A3:E200");
 output_exp_fixed_cost_2 to SheetWrite(excel,"'cost'!G3:K200");
 output_exp_fixed_cost_3 to SheetWrite(excel,"'cost'!M3:P200");
 

如您所见,model 表示当 .dat 文件中的音量 = [40,70,20] 时,A[h] 和 B[h] 相同。为什么 sum(n in order) 等于 sum(n in order: (n-1) in order)?当 volume = [40,40,80] 时不会出现此问题,然后 model 完美运行。我真的不知道发生了什么......我知道这是一个精心设计的 model,但如果有人可以提供帮助,请告诉我!亲切的问候。

你的最优解300中,A和B相同,但公式不同

如果添加新约束

A[1]!=B[1];

然后你得到一个新的解决方案 objective 375