-
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.
Pulled from clingo (MIT) and from Draco (BSD 3 Clause)
- Loading branch information
1 parent
664d615
commit 476a43c
Showing
3 changed files
with
102 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
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. |