Hi Azadeh,
You can use the generic set of constraints _con
, indexed over 1.._ncons
, and the constraints suffixes .ub
and .lb
. Ampl is going to rearrange your constraints to write the matrix, and each constraint will have ub and lb (upper/lower bounds), which are accessible with these suffixes.
Then, you can loop over the constraints and get these values easily:
# Option 1 with printf
printf {i in 1.._ncons} "Const %d LB: %f UB: %f\n", i, _con[i].lb, _con[i].ub;
# Option 1 with display
display {i in 1.._ncons} (_con[i].lb, _con[i].ub);
With the network example (model and data file) you should get the following output:
ampl: model net1.mod
ampl: data net1.dat
ampl: printf {i in 1.._ncons} "Const %d LB: %f UB: %f\n", i, _con[i].lb, _con[i].ub;
Const 1 LB: -450.000000 UB: -450.000000
Const 2 LB: 0.000000 UB: 0.000000
Const 3 LB: 0.000000 UB: 0.000000
Const 4 LB: 90.000000 UB: 90.000000
Const 5 LB: 120.000000 UB: 120.000000
Const 6 LB: 120.000000 UB: 120.000000
Const 7 LB: 70.000000 UB: 70.000000
Const 8 LB: 50.000000 UB: 50.000000
ampl: display {i in 1.._ncons} (_con[i].lb, _con[i].ub);
: _con[i].lb _con[i].ub :=
1 -450 -450
2 0 0
3 0 0
4 90 90
5 120 120
6 120 120
7 70 70
8 50 50
;
Remember that the b
value you are getting is not the one sent to the solver, as AMPL’s presolve reduces the size and complexity of the original matrices.
Another way is to use the expand
command.
ampl: model net1.mod
ampl: data net1.dat
ampl: expand;
minimize Total_Cost:
2.5*Ship['PITT','NE'] + 3.5*Ship['PITT','SE'] + 1.7*Ship['NE','BOS'] +
0.7*Ship['NE','EWR'] + 1.3*Ship['NE','BWI'] + 1.3*Ship['SE','EWR'] +
0.8*Ship['SE','BWI'] + 0.2*Ship['SE','ATL'] + 2.1*Ship['SE','MCO'];
subject to Balance['PITT']:
-Ship['PITT','NE'] - Ship['PITT','SE'] = -450;
subject to Balance['NE']:
Ship['PITT','NE'] - Ship['NE','BOS'] - Ship['NE','EWR'] -
Ship['NE','BWI'] = 0;
subject to Balance['SE']:
Ship['PITT','SE'] - Ship['SE','EWR'] - Ship['SE','BWI'] -
Ship['SE','ATL'] - Ship['SE','MCO'] = 0;
subject to Balance['BOS']:
Ship['NE','BOS'] = 90;
subject to Balance['EWR']:
Ship['NE','EWR'] + Ship['SE','EWR'] = 120;
subject to Balance['BWI']:
Ship['NE','BWI'] + Ship['SE','BWI'] = 120;
subject to Balance['ATL']:
Ship['SE','ATL'] = 70;
subject to Balance['MCO']:
Ship['SE','MCO'] = 50;
And from this output, rewriting in the Ax <= b form.
By the way, there is an AMPL API for Matlab that could help in your application.
Hope it helps!
Marcos