Skip to content

Instantly share code, notes, and snippets.

@Strernd
Last active Dec 5, 2016
Embed
What would you like to do?
/*********************************************
* OPL 12.7.0.0 Model
* Author: Bernd
* Creation Date: 26.11.2016 at 18:12:32
*********************************************/
range warehouses = 1..3;
range retailers = 1..4;
int cost[warehouses][retailers] = [[35,30,40,32],[37,40,42,25],[40,15,20,28]];
int stock[warehouses] = [1200,1000,800];
int demand[retailers] = [1100,400,750,750];
dvar float+ transport[warehouses][retailers];
dexpr float obj = sum (w in warehouses, r in retailers)
transport[w][r] * cost[w][r];
minimize obj;
subject to{
warehouse01:
(sum (r in retailers)
transport[1][r]) <= stock[1];
warehouse02:
(sum (r in retailers)
transport[2][r]) <= stock[2];
warehouse03:
(sum (r in retailers)
transport[3][r]) <= stock[3];
retailer01:
(sum (w in warehouses)
transport[w][1]) == demand[1];
retailer02:
(sum (w in warehouses)
transport[w][2]) == demand[2];
retailer03:
(sum (w in warehouses)
transport[w][3]) == demand[3];
retailer04:
(sum (w in warehouses)
transport[w][4]) == demand[4];
}
execute{
if(cplex.getCplexStatus() == 1)
{
writeln("dual value of constraint 1: ",warehouse01.dual);
writeln("dual value of constraint 2: ",warehouse02.dual);
writeln("dual value of constraint 3: ",warehouse03.dual);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment