Hi,
I have the following transshipment problem:
Number of sources: 2 ( found in code as supplyLength)
Number of destinations: 3 (found in code as demandLength)
The demand for each of the 3 destination points:
[150, 100, 150] (found in code as demand[])
The quantity available at each 2 source points:
[300, 100] (found in code as supply[])
The number of transshipment points 2 (found in code as transPoints)
The matrix of costs from a source to a transshipment point : (found in code as costsWT[][])
7 5
3 4
The matrix of costs from a transshipment point to a destination point : (found in code as costsTC[][])
8 5 7
5 6 10
I am stuck at writing the constraint for the transshipment points - the sum of all flows that enter a transshipment point = the sum of all flows that leaves the transshipment point. ( in my case
7 + 3 = 8 + 5 + 7
5 + 4 = 5 + 6 + 10
)
Below is what I have so far:
IntVar[][] result = new IntVar[supplyLength + transPoints][demandLength + transPoints];
for (int i = 0; i < supplyLength + transPoints ; i++) {
for (int j = 0; j < demandLength + transPoints; j++) {
result[i][j] = model.intVar("result_" + i + j, 0,100);
}
}
//sum of source row values <= supply
for (int i = 0; i < supplyLength; i++) {
model.sum(result[i],"<=",supply[i]).post();
}
//sum of column values = demand
int demandIndex = 0;
for(int i = transPoints; i < demandLength + transPoints; i++) {
IntVar[] col = new IntVar[supplyLength + transPoints];
for(int j = 0; j < supplyLength + transPoints; j++) {
col[j] = result[j][i];
}
model.sum(col, "=", demand[demandIndex]).post();
demandIndex ++;
}
IntVar tot_cost = model.intVar("tot_cost", 0, 9999, true);
//flow in = flow out ??
model.setObjective(Model.MINIMIZE, tot_cost);
Solver solver = model.getSolver();
while(solver.solve())
{
System.out.println(solver.getSolutionCount() + "----------" );
}
Can you please help me understand how to write these constraints and tell me if it's ok to use a result matrix?
Thank you!
Ungurean Andreea