-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Answer Set Programming and Linear Programming (#7184)
* Add Answer Set Programming * Add Answer Set Programming examples Pulled from clingo (MIT) and from Draco (BSD 3 Clause) * Add Linear Programming language entry * Add Linear Programming samples * Add heuristic for Linear Programming Linear programs must have an objective * Make linear programming heuristic more precise Exactly match the object line --------- Co-authored-by: Colin Seymour <[email protected]>
- Loading branch information
1 parent
7e04d26
commit 30c4668
Showing
13 changed files
with
249 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include <incmode>. | ||
|
||
% 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule asp-syntax-highlight
added at
913ac8
31 changes: 31 additions & 0 deletions
31
vendor/licenses/git_submodule/asp-syntax-highlight.dep.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: [] |