Need help Cplex code about optimization waste collection with collection point my code seem not right

36 Views Asked by At

I am currently working on optimizing waste collection and attempting to create a Traveling Salesman Problem (TSP) model that incorporates collection points.

The primary objective of this code is to efficiently collect waste from all the general bins using a single vehicle. When the vehicle reaches its capacity, it should unload the waste at the nearest collection point bin and then continue the collection process until all the general bins have been serviced.

If you have any insights or suggestions on how to approach this problem, I would appreciate your input.

my code and data file shown as follows;

My code;

int N = 5;
int Q = 10;

{int} nodei = ...;
{int} nodej = ...;
{int} collection = ...;

float d[nodei][nodej] = ...;
float Node_i_to_c[nodei][collection] = ...;
float w[nodei]= ...;
float Capacity[nodei]= ...;

 // Decision variables
dvar boolean x[nodei][nodej];
dvar boolean y[nodei][collection];
dvar boolean v[collection];
dvar int+ u[nodei];

// Objective function
minimize
    sum(i in nodei, j in nodej) d[i][j] * x[i][j];

// Constraints
subject to {
    // Each customer visited exactly once
    forall(i in nodei)
        sum(j in nodej: i != j) x[i][j] == 1;

    forall(j in nodej)
      sum(i in nodei: i != j) x[i][j] == 1;
      
      // Unloading constraints
      
    forall(i in nodei: i != 1, b in collection)
        u[i] - u[b] + (N - 1)*y[i][b] <= N - 2;
        
    forall(i in nodei: i != 1, b in collection)
      u[i] <= N*(1-v[b]);
      
      // Capacity constraints
      
    forall(i in nodei)
      sum(b in collection) w[i]*y[i][b] <= Q;    
 
    forall(b in collection)
      sum(i in nodei) w[i]*y[i][b] <= Capacity[b];   
      
      // Visit sequence constraints   
      
    forall(i in nodei: i != 1)
      N>=u[i]>=2;
      
    u[1] == 1;
}

My data file;

nodei = {1, 2, 3, 4, 5};
 nodej = {1, 2, 3, 4, 5};
 collection = {1, 2};
 
w = [0, 5, 6, 8, 4];
Capacity = [15, 18];

d =
[[0.0,     0.5,  0.0765,  0.0758,  0.1],
[0.5,     0.0 , 0.4,     0.5,     0.4],
[0.0765,  0.4,  0.0 ,    0.0447,  0.017],
[0.0758,  0.5,  0.0447,  0.0,     0.0739],
[0.1  ,   0.4,  0.017,   0.0739,  0.0]];

Node_i_to_c =
[[0.0047,  0.0047],
[0.5,     0.5],
[0.0621,  0.0839],
[0.0701,  0.0729],
[0.0902,  0.1]];

I've tried to implement this code and the answer seems not right, the answer shown as follows;

// solution (optimal) with objective 0.9686
// Quality Incumbent solution:
// MILP objective                                 9.6860000000e-01
// MILP solution norm |x| (Total, Max)            1.40000e+01  2.00000e+00
// MILP solution error (Ax=b) (Total, Max)        0.00000e+00  0.00000e+00
// MILP x bound error (Total, Max)                0.00000e+00  0.00000e+00
// MILP x integrality error (Total, Max)          0.00000e+00  0.00000e+00
// MILP slack bound error (Total, Max)            0.00000e+00  0.00000e+00
// 

x = [[0
             0 0 1 0]
             [0 0 0 0 1]
             [0 1 0 0 0]
             [1 0 0 0 0]
             [0 0 1 0 0]];
u = [1 2 2 2 2];
y = [[0 0]
             [0 0]
             [0 0]
             [0 0]
             [0 0]];
v = [0 0];

I need some help from the experts to amend the code in the correct direction. thank you in advance.

0

There are 0 best solutions below