From 0bccf97d16241a2044288623114c17a97a6f54a7 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Tue, 3 Feb 2015 08:56:30 -0800 Subject: [PATCH 1/6] Add support for the AMPL modeling and script language --- lib/linguist/languages.yml | 10 ++++++++++ samples/AMPL/diet.dat | 32 ++++++++++++++++++++++++++++++++ samples/AMPL/diet.mod | 27 +++++++++++++++++++++++++++ samples/AMPL/diet.run | 25 +++++++++++++++++++++++++ samples/AMPL/toy.ampl | 25 +++++++++++++++++++++++++ 5 files changed, 119 insertions(+) create mode 100644 samples/AMPL/diet.dat create mode 100644 samples/AMPL/diet.mod create mode 100644 samples/AMPL/diet.run create mode 100644 samples/AMPL/toy.ampl diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 413683e5..b5062fd9 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -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" diff --git a/samples/AMPL/diet.dat b/samples/AMPL/diet.dat new file mode 100644 index 00000000..c263803c --- /dev/null +++ b/samples/AMPL/diet.dat @@ -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 ; diff --git a/samples/AMPL/diet.mod b/samples/AMPL/diet.mod new file mode 100644 index 00000000..c831a6c6 --- /dev/null +++ b/samples/AMPL/diet.mod @@ -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]; diff --git a/samples/AMPL/diet.run b/samples/AMPL/diet.run new file mode 100644 index 00000000..ded2786d --- /dev/null +++ b/samples/AMPL/diet.run @@ -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; diff --git a/samples/AMPL/toy.ampl b/samples/AMPL/toy.ampl new file mode 100644 index 00000000..0ca0c7cf --- /dev/null +++ b/samples/AMPL/toy.ampl @@ -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; From 407dbbb7fb7ed7a91f26896466fdf6e1fbc9bf98 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Tue, 3 Feb 2015 09:52:06 -0800 Subject: [PATCH 2/6] Mark AMPL with `tm_scope: none` because it doesn't have grammar info --- lib/linguist/languages.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index b5062fd9..feaa1280 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -49,6 +49,7 @@ AMPL: - .dat - .mod - .run + tm_scope: none ace_mode: text ANTLR: From 1cdd3c55aba439733ab1df7e3acc4b70bf6523c0 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Wed, 25 Feb 2015 11:37:40 -0800 Subject: [PATCH 3/6] Add AMPL grammar --- .gitmodules | 3 +++ grammars.yml | 2 ++ vendor/grammars/ampl | 1 + 3 files changed, 6 insertions(+) create mode 160000 vendor/grammars/ampl diff --git a/.gitmodules b/.gitmodules index 136013b2..134004a4 100644 --- a/.gitmodules +++ b/.gitmodules @@ -630,3 +630,6 @@ [submodule "vendor/grammars/Lean.tmbundle"] path = vendor/grammars/Lean.tmbundle url = https://github.com/leanprover/Lean.tmbundle +[submodule "vendor/grammars/ampl"] + path = vendor/grammars/ampl + url = https://github.com/ampl/sublime-ampl diff --git a/grammars.yml b/grammars.yml index 6d933a09..3b40a3b9 100644 --- a/grammars.yml +++ b/grammars.yml @@ -143,6 +143,8 @@ vendor/grammars/actionscript3-tmbundle: - text.xml.flex-config vendor/grammars/ada.tmbundle: - source.ada +vendor/grammars/ampl: +- source.ampl vendor/grammars/ant.tmbundle: - text.xml.ant vendor/grammars/antlr.tmbundle: diff --git a/vendor/grammars/ampl b/vendor/grammars/ampl new file mode 160000 index 00000000..2e399ebf --- /dev/null +++ b/vendor/grammars/ampl @@ -0,0 +1 @@ +Subproject commit 2e399ebf4aec6b5b81f01d4cbee965f77852ce86 From 13eb7c796ed965f49df0d8a58f05b615a4815669 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Wed, 25 Feb 2015 12:59:23 -0800 Subject: [PATCH 4/6] Remove .dat, .mod and .run AMPL extensions as they are ambiguous As discussed in #2073 adding these extensions will require more work to avoid incorrect language detection. --- lib/linguist/languages.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index feaa1280..57777f64 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -46,9 +46,6 @@ AMPL: color: "#00008B" extensions: - .ampl - - .dat - - .mod - - .run tm_scope: none ace_mode: text From e093ac843f92b698340d1953b9bdc9f77701cd3d Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Wed, 25 Feb 2015 14:22:45 -0800 Subject: [PATCH 5/6] Remove AMPL samples using .mod, .dat and .run extensions --- samples/AMPL/diet.dat | 32 -------------------------------- samples/AMPL/diet.mod | 27 --------------------------- samples/AMPL/diet.run | 25 ------------------------- 3 files changed, 84 deletions(-) delete mode 100644 samples/AMPL/diet.dat delete mode 100644 samples/AMPL/diet.mod delete mode 100644 samples/AMPL/diet.run diff --git a/samples/AMPL/diet.dat b/samples/AMPL/diet.dat deleted file mode 100644 index c263803c..00000000 --- a/samples/AMPL/diet.dat +++ /dev/null @@ -1,32 +0,0 @@ - -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 ; diff --git a/samples/AMPL/diet.mod b/samples/AMPL/diet.mod deleted file mode 100644 index c831a6c6..00000000 --- a/samples/AMPL/diet.mod +++ /dev/null @@ -1,27 +0,0 @@ - -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]; diff --git a/samples/AMPL/diet.run b/samples/AMPL/diet.run deleted file mode 100644 index ded2786d..00000000 --- a/samples/AMPL/diet.run +++ /dev/null @@ -1,25 +0,0 @@ -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; From 51af1bd162eccaddf3f5d224dd4cbbbb3385d28e Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 26 Feb 2015 10:40:56 -0800 Subject: [PATCH 6/6] Use AMPL grammar --- lib/linguist/languages.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 57777f64..d1348dc0 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -46,7 +46,7 @@ AMPL: color: "#00008B" extensions: - .ampl - tm_scope: none + tm_scope: source.ampl ace_mode: text ANTLR: