Add support for the AMPL modeling and script language

This commit is contained in:
Victor Zverovich
2015-02-03 08:56:30 -08:00
parent 739b512cee
commit 0bccf97d16
5 changed files with 119 additions and 0 deletions

View File

@@ -41,6 +41,16 @@ AGS Script:
tm_scope: source.c++
ace_mode: c_cpp
AMPL:
type: programming
color: "#00008B"
extensions:
- .ampl
- .dat
- .mod
- .run
ace_mode: text
ANTLR:
type: programming
color: "#9DC3FF"

32
samples/AMPL/diet.dat Normal file
View File

@@ -0,0 +1,32 @@
param: FOOD: cost f_min f_max :=
"Quarter Pounder w/ Cheese" 1.84 . .
"McLean Deluxe w/ Cheese" 2.19 . .
"Big Mac" 1.84 . .
"Filet-O-Fish" 1.44 . .
"McGrilled Chicken" 2.29 . .
"Fries, small" .77 . .
"Sausage McMuffin" 1.29 . .
"1% Lowfat Milk" .60 . .
"Orange Juice" .72 . . ;
param: NUTR: n_min n_max :=
Cal 2000 .
Carbo 350 375
Protein 55 .
VitA 100 .
VitC 100 .
Calc 100 .
Iron 100 . ;
param amt (tr):
Cal Carbo Protein VitA VitC Calc Iron :=
"Quarter Pounder w/ Cheese" 510 34 28 15 6 30 20
"McLean Deluxe w/ Cheese" 370 35 24 15 10 20 20
"Big Mac" 500 42 25 6 2 25 20
"Filet-O-Fish" 370 38 14 2 0 15 10
"McGrilled Chicken" 400 42 31 8 15 15 8
"Fries, small" 220 26 3 0 15 0 2
"Sausage McMuffin" 345 27 15 4 0 20 15
"1% Lowfat Milk" 110 12 9 10 4 30 0
"Orange Juice" 80 20 1 2 120 2 2 ;

27
samples/AMPL/diet.mod Normal file
View File

@@ -0,0 +1,27 @@
set NUTR ordered;
set FOOD ordered;
param cost {FOOD} >= 0;
param f_min {FOOD} >= 0, default 0;
param f_max {j in FOOD} >= f_min[j], default Infinity;
param n_min {NUTR} >= 0, default 0;
param n_max {i in NUTR} >= n_min[i], default Infinity;
param amt {NUTR,FOOD} >= 0;
# --------------------------------------------------------
var Buy {j in FOOD} integer >= f_min[j], <= f_max[j];
# --------------------------------------------------------
minimize Total_Cost: sum {j in FOOD} cost[j] * Buy[j];
minimize Nutr_Amt {i in NUTR}: sum {j in FOOD} amt[i,j] * Buy[j];
# --------------------------------------------------------
subject to Diet {i in NUTR}:
n_min[i] <= sum {j in FOOD} amt[i,j] * Buy[j] <= n_max[i];

25
samples/AMPL/diet.run Normal file
View File

@@ -0,0 +1,25 @@
model diet.mod;
data diet2.dat;
param N symbolic in NUTR;
param nstart > 0;
param nstep > 0;
read N, nstart, nstep <- ; # read data interactively
set N_MAX default {};
param N_obj {N_MAX};
param N_dual {N_MAX};
option solver_msg 0;
for {i in nstart .. 0 by -nstep} {
let n_max[N] := i;
solve;
if solve_result = "infeasible" then {
printf "--- infeasible at %d ---\n\n", i;
break;
}
let N_MAX := N_MAX union {i};
let N_obj[i] := Total_Cost;
let N_dual[i] := Diet[N].dual;
}
display N_obj, N_dual;

25
samples/AMPL/toy.ampl Normal file
View File

@@ -0,0 +1,25 @@
# A toy knapsack problem from the LocalSolver docs written in AMPL.
set I;
param Value{I};
param Weight{I};
param KnapsackBound;
var Take{I} binary;
maximize TotalValue: sum{i in I} Take[i] * Value[i];
s.t. WeightLimit: sum{i in I} Take[i] * Weight[i] <= KnapsackBound;
data;
param:
I: Weight Value :=
0 10 1
1 60 10
2 30 15
3 40 40
4 30 60
5 20 90
6 20 100
7 2 15;
param KnapsackBound := 102;