diff --git a/.gitmodules b/.gitmodules index 65d5ef54e..b05987659 100644 --- a/.gitmodules +++ b/.gitmodules @@ -275,6 +275,9 @@ [submodule "vendor/grammars/asciidoc.tmbundle"] path = vendor/grammars/asciidoc.tmbundle url = https://github.com/zuckschwerdt/asciidoc.tmbundle +[submodule "vendor/grammars/asp-syntax-highlight"] + path = vendor/grammars/asp-syntax-highlight + url = https://github.com/nickswalker/asp-syntax-highlight.git [submodule "vendor/grammars/asp.tmbundle"] path = vendor/grammars/asp.tmbundle url = https://github.com/textmate/asp.tmbundle diff --git a/grammars.yml b/grammars.yml index 219734dcf..a24778d54 100644 --- a/grammars.yml +++ b/grammars.yml @@ -224,6 +224,8 @@ vendor/grammars/applescript.tmbundle: - source.applescript vendor/grammars/asciidoc.tmbundle: - text.html.asciidoc +vendor/grammars/asp-syntax-highlight: +- source.answersetprogramming vendor/grammars/asp.tmbundle: - source.asp - text.html.asp diff --git a/lib/linguist/heuristics.yml b/lib/linguist/heuristics.yml index d5af8a4fd..3145427bb 100644 --- a/lib/linguist/heuristics.yml +++ b/lib/linguist/heuristics.yml @@ -417,6 +417,11 @@ disambiguations: pattern: '^import [a-z]' - language: Lean 4 pattern: '^import [A-Z]' +- extensions: ['.lp'] + rules: + - language: Linear Programming + pattern: '^(?i:minimize|minimum|min|maximize|maximum|max)(?i:\s+multi-objectives)?$' + - language: Answer Set Programming - extensions: ['.ls'] rules: - language: LoomScript diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index b97889373..d4b8bfe3b 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -307,6 +307,16 @@ AngelScript: codemirror_mode: clike codemirror_mime_type: text/x-c++src language_id: 389477596 +Answer Set Programming: + type: programming + color: "#A9CC29" + extensions: + - ".lp" + interpreters: + - "clingo" + tm_scope: source.answersetprogramming + ace_mode: prolog + language_id: 433009171 Ant Build System: type: data color: "#A9157E" @@ -3915,6 +3925,13 @@ Limbo: tm_scope: none ace_mode: text language_id: 201 +Linear Programming: + type: programming + extensions: + - ".lp" + tm_scope: none + ace_mode: text + language_id: 377204539 Linker Script: type: data extensions: diff --git a/samples/Answer Set Programming/15puzzle-encoding.lp b/samples/Answer Set Programming/15puzzle-encoding.lp new file mode 100644 index 000000000..74b37c933 --- /dev/null +++ b/samples/Answer Set Programming/15puzzle-encoding.lp @@ -0,0 +1,43 @@ +#include . + +% if set to one, permits consecutive moves in one time step +% this will not provide optimal plans but usually finds solutions much faster +#const consecutive = 0. + +#program base. + +% neighborhood relation +d(1,0;0,1;-1,0;0,-1). +n((X,Y),(X+DX,Y+DY)) :- dim((X,Y)), dim((X+DX,Y+DY)), d(DX,DY). + +% positions at time step zero +at(0,(X,Y),N) :- in(X,Y,N). + +#program step(t). + +% guess moves +1 { move(t,A,B) : n(A,B) } 1 :- dim(B), not at(t-1,B,_). +0 { move(t,A,B) : n(A,B) } 1 :- move(t,B,_), consecutive == 1. + +% check moves + :- 2 { move(t,A,B) }, dim(A). + +% state transition +at(t,A,N) :- at(t-1,A,N), not move(t,A,_). +at(t,B,N) :- at(t-1,A,N), move(t,A,B). + +% some redundant constraints + :- move(t,A,_), not at(t-1,A,_). + :- move(t,A,B), move(t-1,B,A), consecutive != 1. + +#program check(t). + +% check domain knowledge + :- not 1 { not at(t,A,_) : dim(A) } 1. + :- 2 { at(t,A,N) }, dim(A). + +% check goal + :- go(X,Y,N), not at(t,(X,Y),N), query(t). + +#show move/3. +#show at/3. \ No newline at end of file diff --git a/samples/Answer Set Programming/apt.lp b/samples/Answer Set Programming/apt.lp new file mode 100644 index 000000000..470e1b7bc --- /dev/null +++ b/samples/Answer Set Programming/apt.lp @@ -0,0 +1,34 @@ +% implementation of APT + +#include "asp/define.lp". +#include "asp/generate.lp". +#include "asp/hard.lp". + +:~ type(E,quantitative), channel(E,x), priority(E,P). [1@P,E] +:~ type(E,quantitative), channel(E,y), priority(E,P). [1@P,E] +:~ type(E,quantitative), channel(E,size), priority(E,P). [2@P,E] +:~ type(E,quantitative), channel(E,color), priority(E,P). [3@P,E] + +:~ type(E,ordinal), channel(E,x), priority(E,P). [1@P,E] +:~ type(E,ordinal), channel(E,y), priority(E,P). [1@P,E] +:~ type(E,ordinal), channel(E,color), priority(E,P). [2@P,E] +:~ type(E,ordinal), channel(E,size), priority(E,P). [3@P,E] + +:~ type(E,nominal), channel(E,x), priority(E,P). [1@P,E] +:~ type(E,nominal), channel(E,y), priority(E,P). [1@P,E] +:~ type(E,nominal), channel(E,color), priority(E,P). [2@P,E] +:~ type(E,nominal), channel(E,shape), priority(E,P). [3@P,E] +:~ type(E,nominal), channel(E,size), priority(E,P). [4@P,E] + +:- channel(_,text). +:- channel(_,detail). +:- channel(_,row). +:- channel(_,column). + +% don't bin, use log, or aggregate +:- bin(_). +:- log(_). +:- aggregate(_,_). + +#show mark/1. +#show channel/2. diff --git a/samples/Answer Set Programming/onmodel-py.lp b/samples/Answer Set Programming/onmodel-py.lp new file mode 100644 index 000000000..7b7801d38 --- /dev/null +++ b/samples/Answer Set Programming/onmodel-py.lp @@ -0,0 +1,25 @@ +#script (python) + +import clingo + +def main(prg): + def on_model(m): + print("shown") + print(" positive: " + ", ".join(map(str, m.symbols(shown=True)))) + print(" negative: " + ", ".join(map(str, m.symbols(shown=True, complement=True)))) + print("atoms") + print(" positive: " + ", ".join(map(str, m.symbols(atoms=True)))) + print(" negative: " + ", ".join(map(str, m.symbols(atoms=True, complement=True)))) + print("terms") + print(" positive: " + ", ".join(map(str, m.symbols(terms=True)))) + print(" negative: " + ", ".join(map(str, m.symbols(terms=True, complement=True)))) + + prg.ground([("base", [])]) + prg.solve(on_model=on_model) + +#end. + +{a}. +b :- a. +#show c : a. +#show b/0. \ No newline at end of file diff --git a/samples/Linear Programming/Multiobj.lp b/samples/Linear Programming/Multiobj.lp new file mode 100644 index 000000000..6a5df350c --- /dev/null +++ b/samples/Linear Programming/Multiobj.lp @@ -0,0 +1,19 @@ +\ Model Multiobj +\ LP format - for model browsing. Use MPS format to capture full model detail. +Maximize multi-objectives + Set0: Priority=3 Weight=1 AbsTol=1 RelTol=0.01 + El0 + El1 + El2 + El3 + El4 + El5 + El6 + El7 + El8 + El9 + Set1: Priority=2 Weight=0.25 AbsTol=2 RelTol=0.01 + El5 + El6 + El7 + El8 + El9 + El15 + El16 + El17 + El18 + El19 + Set2: Priority=2 Weight=1.25 AbsTol=3 RelTol=0.01 + El3 + El4 + El6 + El7 + El13 + El14 + El16 + El17 + Set3: Priority=1 Weight=1 AbsTol=4 RelTol=0.01 + El3 + El4 + El5 + El9 + El10 + El11 + El15 + El16 + El17 +Subject To + Budget: El0 + El1 + El2 + El3 + El4 + El5 + El6 + El7 + El8 + El9 + El10 + + El11 + El12 + El13 + El14 + El15 + El16 + El17 + El18 + El19 <= 12 +Bounds +Binaries + El0 El1 El2 El3 El4 El5 El6 El7 El8 El9 El10 El11 El12 El13 El14 El15 El16 + El17 El18 El19 +End \ No newline at end of file diff --git a/samples/Linear Programming/diet.lp b/samples/Linear Programming/diet.lp new file mode 100644 index 000000000..892b2a2a3 --- /dev/null +++ b/samples/Linear Programming/diet.lp @@ -0,0 +1,61 @@ +\ This file has been generated by DOcplex +\ ENCODING=ISO-8859-1 +\Problem name: diet + +Minimize + obj: 0.840000000000 Roasted_Chicken + 0.780000000000 Spaghetti_W__Sauce + + 0.270000000000 Tomato,Red,Ripe,Raw + 0.240000000000 Apple,Raw,W_Skin + + 0.320000000000 Grapes + 0.030000000000 Chocolate_Chip_Cookies + + 0.230000000000 Lowfat_Milk + 0.340000000000 Raisin_Brn + + 0.310000000000 Hotdog +Subject To + c1: 277.400000000000 Roasted_Chicken + 358.200000000000 Spaghetti_W__Sauce + + 25.800000000000 Tomato,Red,Ripe,Raw + 81.400000000000 Apple,Raw,W_Skin + + 15.100000000000 Grapes + 78.100000000000 Chocolate_Chip_Cookies + + 121.200000000000 Lowfat_Milk + 115.100000000000 Raisin_Brn + + 242.100000000000 Hotdog- Rgc1 = 2500 + c2: 21.900000000000 Roasted_Chicken + 80.200000000000 Spaghetti_W__Sauce + + 6.200000000000 Tomato,Red,Ripe,Raw + 9.700000000000 Apple,Raw,W_Skin + + 3.400000000000 Grapes + 6.200000000000 Chocolate_Chip_Cookies + + 296.700000000000 Lowfat_Milk + 12.900000000000 Raisin_Brn + + 23.500000000000 Hotdog- Rgc2 = 1600 + c3: 1.800000000000 Roasted_Chicken + 2.300000000000 Spaghetti_W__Sauce + + 0.600000000000 Tomato,Red,Ripe,Raw + 0.200000000000 Apple,Raw,W_Skin + + 0.100000000000 Grapes + 0.400000000000 Chocolate_Chip_Cookies + + 0.100000000000 Lowfat_Milk + 16.800000000000 Raisin_Brn + + 2.300000000000 Hotdog- Rgc3 = 30 + c4: 77.400000000000 Roasted_Chicken + 3055.200000000000 Spaghetti_W__Sauce + + 766.300000000000 Tomato,Red,Ripe,Raw + 73.100000000000 Apple,Raw,W_Skin + + 24 Grapes + 101.800000000000 Chocolate_Chip_Cookies + + 500.200000000000 Lowfat_Milk + 1250.200000000000 Raisin_Brn- Rgc4 = 50000 + c5: 11.600000000000 Spaghetti_W__Sauce + 1.400000000000 Tomato,Red,Ripe,Raw + + 3.700000000000 Apple,Raw,W_Skin + 0.200000000000 Grapes + 4 Raisin_Brn- + Rgc5 = 100 + c6: 58.300000000000 Spaghetti_W__Sauce + 5.700000000000 Tomato,Red,Ripe,Raw + + 21 Apple,Raw,W_Skin + 4.100000000000 Grapes + + 9.300000000000 Chocolate_Chip_Cookies + 11.700000000000 Lowfat_Milk + + 27.900000000000 Raisin_Brn + 18 Hotdog- Rgc6 = 300 + c7: 42.200000000000 Roasted_Chicken + 8.200000000000 Spaghetti_W__Sauce + + Tomato,Red,Ripe,Raw + 0.300000000000 Apple,Raw,W_Skin + + 0.200000000000 Grapes + 0.900000000000 Chocolate_Chip_Cookies + + 8.100000000000 Lowfat_Milk + 4 Raisin_Brn + 10.400000000000 Hotdog- Rgc7 + = 100 + +Bounds + Roasted_Chicken <= 10 + Spaghetti_W__Sauce <= 10 + Tomato,Red,Ripe,Raw <= 10 + Apple,Raw,W_Skin <= 10 + Grapes <= 10 + Chocolate_Chip_Cookies <= 10 + Lowfat_Milk <= 10 + Raisin_Brn <= 10 + Hotdog <= 10 +-500 <= Rgc1 <= 0 +-800 <= Rgc2 <= 0 +-20 <= Rgc3 <= 0 +-45000 <= Rgc4 <= 0 +-75 <= Rgc5 <= 0 +-300 <= Rgc6 <= 0 +-50 <= Rgc7 <= 0 +End \ No newline at end of file diff --git a/test/test_heuristics.rb b/test/test_heuristics.rb index a480cf3cc..d20c4f84b 100755 --- a/test/test_heuristics.rb +++ b/test/test_heuristics.rb @@ -615,6 +615,13 @@ def test_lisp_by_heuristics }, "main.lisp") end + def test_lp_by_heuristics + assert_heuristics({ + "Answer Set Programming" => all_fixtures("Answer Set Programming", "*.lp"), + "Linear Programming" => all_fixtures("Linear Programming", "*.lp") + }) + end + def test_ls_by_heuristics assert_heuristics({ "LiveScript" => all_fixtures("LiveScript", "*.ls"), diff --git a/vendor/README.md b/vendor/README.md index f2b1a53f6..5f0132882 100644 --- a/vendor/README.md +++ b/vendor/README.md @@ -32,6 +32,7 @@ This is a list of grammars that Linguist selects to provide syntax highlighting - **Alpine Abuild:** [atom/language-shellscript](https://github.com/atom/language-shellscript) - **Altium Designer:** [textmate/ini.tmbundle](https://github.com/textmate/ini.tmbundle) - **AngelScript:** [wronex/sublime-angelscript](https://github.com/wronex/sublime-angelscript) +- **Answer Set Programming:** [nickswalker/asp-syntax-highlight](https://github.com/nickswalker/asp-syntax-highlight) - **Ant Build System:** [textmate/ant.tmbundle](https://github.com/textmate/ant.tmbundle) - **Antlers:** [Stillat/vscode-antlers-language-server](https://github.com/Stillat/vscode-antlers-language-server) - **ApacheConf:** [textmate/apache.tmbundle](https://github.com/textmate/apache.tmbundle) diff --git a/vendor/grammars/asp-syntax-highlight b/vendor/grammars/asp-syntax-highlight new file mode 160000 index 000000000..913ac8ffc --- /dev/null +++ b/vendor/grammars/asp-syntax-highlight @@ -0,0 +1 @@ +Subproject commit 913ac8ffc70f5d72c07d74637511d632c175c410 diff --git a/vendor/licenses/git_submodule/asp-syntax-highlight.dep.yml b/vendor/licenses/git_submodule/asp-syntax-highlight.dep.yml new file mode 100644 index 000000000..e4ecd31d8 --- /dev/null +++ b/vendor/licenses/git_submodule/asp-syntax-highlight.dep.yml @@ -0,0 +1,31 @@ +--- +name: asp-syntax-highlight +version: 913ac8ffc70f5d72c07d74637511d632c175c410 +type: git_submodule +homepage: https://github.com/nickswalker/asp-syntax-highlight.git +license: mit +licenses: +- sources: LICENSE + text: | + MIT License + + Copyright (c) 2017 Arnaud Belcour + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +notices: []