-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from ADDALemos/master
All in one
- Loading branch information
Showing
52 changed files
with
3,372 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,57 @@ | ||
*.idea | ||
*~ | ||
# Compiled Object files | ||
*.slo | ||
*.lo | ||
*.o | ||
*.obj | ||
|
||
# Precompiled Headers | ||
*.gch | ||
*.pch | ||
|
||
# Compiled Dynamic libraries | ||
*.so | ||
*.dylib | ||
*.dll | ||
|
||
# Fortran module files | ||
*.mod | ||
*.smod | ||
|
||
# Compiled Static libraries | ||
*.lai | ||
*.la | ||
*.a | ||
*.lib | ||
|
||
# Executables | ||
*.exe | ||
*.out | ||
*.app | ||
*.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
|
||
# Icon must end with two \r | ||
Icon | ||
|
||
|
||
# Thumbnails | ||
._* | ||
|
||
# Files that might appear in the root of a volume | ||
.DocumentRevisions-V100 | ||
.fseventsd | ||
.Spotlight-V100 | ||
.TemporaryItems | ||
.Trashes | ||
.VolumeIcon.icns | ||
.com.apple.timemachine.donotpresent | ||
|
||
# Directories potentially created on remote AFP share | ||
.AppleDB | ||
.AppleDesktop | ||
Network Trash Folder | ||
Temporary Items | ||
.apdisk |
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,149 @@ | ||
#include <incmode>. | ||
|
||
#program base. | ||
timeStep(T):-obs_vlabel(_,_,_,T). | ||
vertex(V,0):-edge(V,_,0). | ||
vertex(V,0):-edge(_,V,0). | ||
visit(P,V,0,0):- V = #min{Y : vertex(Y,0)},exp(P). | ||
input(P,V) :- exp(P), vertex(V,0), not function(_,V,0),not edge(U,V,0) : edge(U,V,0), U != V. | ||
sign(0;1). | ||
complement(T,S) :- sign(S),sign(T),T!=S. | ||
vlabel(P,V,S,T) :- obs_vlabel(P,V,S,T), exp(P), vertex(V,0). | ||
goal(V,TI) :- TI=#max{T:obs_vlabel(P,V,_,T)},vertex(V,0),exp(P). | ||
%max(V*T):-T=#max{S:timeStep(S)},V=#count{W:vertex(W,0)}. | ||
function(N,V,0) :- functionOr(N,V,0). | ||
function(N,V,0) :- functionAnd(N,V,0). | ||
function(N,V,0) :- functionNot(N,V,0). | ||
function(N,V,0) :- functionId(N,V,0). | ||
isTemp(temporary(V),0):-vertex(temporary(V),0). | ||
isFunction(W,O):-regulator(N,W),function(N,O,_). | ||
isFunction(W,O):-regulator(N,W),function(N,V,_),isTemp(V,0), V!=O,isFunction(V,O). | ||
#program step(t). | ||
%Generate | ||
%Profile, Vertex, TimeStep, Iteration | ||
|
||
{visit(P,V,TS,t): vlabel(P,V,_,TS)}=1. | ||
%Define | ||
%Assign temporary vertex | ||
vlabel(P,V,S,t):- vertex(V,_), exp(P), compute(P,V,S,t), complement(S,T),not vlabel(P,V,T,_). | ||
current_vlabel(P,V,S,t):-T=#max{TS:visit(P,V,TS,_)},vlabel(P,V,S,T). | ||
current_vlabel(P,V,S,t):-vlabel(P,V,S,t). | ||
isTemp(temporary(V),t):-vertex(temporary(V),t). | ||
function(N,V,t) :- functionOr(N,V,t). | ||
function(N,V,t) :- functionAnd(N,V,t). | ||
function(N,V,t) :- functionNot(N,V,t). | ||
function(N,V,t) :- functionId(N,V,t). | ||
%Compute the values | ||
compute(P,O,1,t):- functionAnd(N,O,0), noneNegative(O,N,P,t), vertex(O,_), exp(P). | ||
compute(P,O,0,t):- functionAnd(N,O,0), not noneNegative(O,N,P,t), vertex(O,_), exp(P), timeStep(TI). | ||
|
||
compute(P,O,1,t):- functionOr(N,O,0),not nonePositive(O,N,P,t), vertex(O,_), exp(P),timeStep(TI). | ||
compute(P,O,0,t):- functionOr(N,O,0),nonePositive(O,N,P,t), vertex(O,_), exp(P). | ||
|
||
compute(P,O,S,t):- functionNot(N,O,0), regulatorSign(P,N,V,T, t), complement(S,T),vertex(O,_), exp(P), not removeRegulator(N,V,_). | ||
compute(P,O,S,t):- functionId(N,O,0), regulatorSign(P,N,V,S,t), vertex(O,_), exp(P), not removeRegulator(N,V,_). %identity | ||
|
||
compute(P,O,1,t) :- not function(_,O,0),vertex(O,_), exp(P), not compute(P,O,0,t),timeStep(TI). | ||
compute(P,O,0,t) :- not function(_,O,0),vertex(O,_), exp(P), not compute(P,O,1,t),timeStep(TI). | ||
|
||
compute(P,O,1,0,t) :- vertex(O,_), exp(P), not compute(P,O,0,0,t). | ||
compute(P,O,0,0,t) :- vertex(O,_), exp(P), not compute(P,O,1,0,t). | ||
|
||
|
||
%Auxiliar functions | ||
%At least one positive and none negative | ||
noneNegative(V,N,P,t) :- not oneNegative(V,N,P,t), onePositive(V,N,P,t). | ||
%At least one negative and none positive | ||
nonePositive(V,N,P,t) :- oneNegative(V,N,P,t), not onePositive(V,N,P,t). | ||
%Time only matters to none temporary nodes. | ||
oneNegative(V,N,P,t):-oneSign(V,N,P,0,t), not isTemp(V,_). | ||
oneNegative(V,N,P,t):-oneSign(V,N,P,0,t), isTemp(V,_). | ||
onePositive(V,N,P,t):-oneSign(V,N,P,1,t), not isTemp(V,_). | ||
onePositive(V,N,P,t):-oneSign(V,N,P,1,t), isTemp(V,_). | ||
oneSign(V,N,P,S,t):- function(N,V,_),isRegulator(N,U,t), current_vlabel(P,U,S,t),not repairSign(P,U,_,t). | ||
oneSign(V,N,P,S,t):- function(N,V,_),isRegulator(N,U,t), repairSign(P,U,S,t),current_vlabel(P,U,_,t). | ||
regulatorSign(P,N,V,1,t):- onePositive(V,N,P,t). | ||
regulatorSign(P,N,V,0,t):- oneNegative(V,N,P,t). | ||
|
||
isRegulator(N,V,t) :- regulator(N,V), not removeRegulator(N,V,_), not negReapir(N,V,_). | ||
negReapir(N,V,t):- repaired(N,V,_), not functionNot(N,_,_). | ||
removeRegulator(N,V,t) :- function(N,U,_), repair(rEdge(V,U),_), not functionNot(N,_,_). | ||
removeRegulator(N,V,t) :- function(N,U,_), removeEdge(V,U,_), not functionNot(N,_,_). | ||
isRegulator(N,temporary(regulator(N,V)),t) :- repaired(N,V,_), not removeRegulator(N,V,_), not functionNot(N,_,_). | ||
isRegulator(temporary(regulator(N,V)),V,t):-repaired(N,V,_), function(temporary(regulator(N,V)),U,_), not removeEdge(V,U,_), not functionNot(N,_,_). | ||
|
||
consistentFunction(P,O,t) :- functionAnd(N,O,_), noneNegative(O,N,P,t), current_vlabel(P,O,1,t), not repair(functionOr(N,O,_),_). | ||
consistentFunction(P,O,t) :- functionAnd(N,O,_), not noneNegative(O,N,P,t), current_vlabel(P,O,0,t),not repair(functionOr(N,O,_),_). | ||
consistentFunction(P,O,t) :- repair(functionAnd(N,O),_), noneNegative(O,N,P,t), current_vlabel(P,O,_,t),repairSign(P,O,1,t), not repair(functionOr(N,O,_),_). | ||
consistentFunction(P,O,t) :- repair(functionAnd(N,O),_), not noneNegative(O,N,P,t), current_vlabel(P,O,_,t),repairSign(P,O,0,t),not repair(functionOr(N,O,_),_). | ||
|
||
consistentFunction(P,O,t) :- functionOr(N,O,_), not nonePositive(O,N,P,t), current_vlabel(P,O,1,t), not repair(functionAnd(N,O,_),_). | ||
consistentFunction(P,O,t) :- functionOr(N,O,_), nonePositive(O,N,P,t),current_vlabel(P,O,0,t), not repair(functionAnd(N,O,_),_). | ||
consistentFunction(P,O,t) :- repair(functionOr(N,O,_),_), not nonePositive(O,N,P,t), repairSign(P,O,1,t),current_vlabel(P,O,_,t), not repair(functionAnd(N,O,_),_). | ||
consistentFunction(P,O,t) :- repair(functionOr(N,O,_),_), nonePositive(O,N,P,t),current_vlabel(P,O,_,t),repairSign(P,O,0,t), not repair(functionAnd(N,O,_),_). | ||
|
||
consistentFunction(P,O,t) :- functionNot(N,O,_),regulatorSign(P,N,O,S,t),current_vlabel(P,O,T,t),S!=T, not repair_functionNot(N,O,_). | ||
consistentFunction(P,O,t) :- repair_functionNot(N,O,_),regulatorSign(P,N,O,S,t),current_vlabel(P,O,_,t),repairSign(P,O,S,t). | ||
consistentFunction(P,O,t) :- functionId(N,O,_),regulatorSign(P,N,O,S,t),current_vlabel(P,O,S,t), not repair_functionNot(N,O,_). | ||
|
||
|
||
:-repairSign(P,U,S,t),visit(P,U,TI,t),obs_vlabel(P,U,T,TI),S!=T. | ||
repairSign(P,U,S,t):-repairSign1(P,U,S,t), isTemp(U,_). | ||
repairSign(P,U,S,t):-repairSign1(P,U,S,t), not isTemp(U,_). | ||
repairSign1(P,U,1,t) :- repair(functionOr(N,U,_),_),not nonePositive(U,N,P,t),exp(P), not repair(functionAnd(N,U,_),_) , not repair_functionNot(N,U,_),timeStep(TI). | ||
repairSign1(P,U,0,t) :- repair(functionOr(N,U,_),_), nonePositive(U,N,P,t),exp(P), not repair(functionAnd(N,U,_),_) , not repair_functionNot(N,U,_). | ||
repairSign1(P,U,1,t) :- repair(functionAnd(N,U,_),_), noneNegative(U,N,P,t), exp(P), not repair(functionOr(N,U,_),_) , not repair_functionNot(N,U,_). | ||
repairSign1(P,U,0,t) :- repair(functionAnd(N,U,_),_), not noneNegative(U,N,P,t), exp(P), not repair(functionOr(N,U,_),_) , not repair_functionNot(N,U,_),timeStep(TI). | ||
repairSign1(P,U,S,t) :- repair_functionNot(N,U,_), functionNot(N,U,_),isRegulator(N,V,_),current_vlabel(P,V,S,t),exp(P), not repair(functionAnd(N,U,_),_) , not repair(functionOr(N,U,_),_). | ||
|
||
|
||
%Possible repairs | ||
pos(functionOr(N,O,0),t) :- repair_g, not nonePositive(O,N,P,t),not functionOr(N,O,0),functionAnd(N,O,0),exp(P),plusinfluence(O,t),timeStep(TI). | ||
pos(functionOr(N,O,0),t) :- repair_g, nonePositive(O,N,P,t),not functionOr(N,O,0),functionAnd(N,O,0),plusinfluence(O,t). | ||
|
||
pos(functionAnd(N,O,0),t) :- repair_g, noneNegative(O,N,P,t),not functionAnd(N,O,0),functionOr(N,O,0),plusinfluence(O,t). | ||
pos(functionAnd(N,O,0),t) :- repair_g, not noneNegative(O,N,P,t),not functionAnd(N,O,0),functionOr(N,O,0),exp(P),plusinfluence(O,t),timeStep(TI). | ||
|
||
plusinfluence(O,t):- edge(V,O,_), edge(W,O,_), W!=O,W!=V,V!=O, not repair(rEdge(V,O),_), not repair(rEdge(W,O),_),not removeEdge(V,O,_),not removeEdge(W,O,_). | ||
|
||
pos(rEdge(U,V),t) :- repair_e, regulator(N,U), function(N,V,_), regulator(N,W), not removeEdge(W,V,_),not isTemp(V,_), not isTemp(U,_). | ||
pos(rEdge(U,D),t) :- repair_e, regulator(N,U), regulator(N,W), function(N,V,_),not removeEdge(W,V,_),isTemp(V,_),isFunction(V,D), not isTemp(D,_), not isTemp(U,_). | ||
removeEdge(U,W,t):-repair(rEdge(U,D),t),regulator(N,U), function(N,W,_), isTemp(W,_),isFunction(W,D), not isTemp(D,_). | ||
removeEdge(U,O,t):-repair(rEdge(U,D),t),regulator(N,U), function(N,O,_). | ||
|
||
pos(regulator(O,V),t):- repair_i, regulator(N,V), function(N,O,_), not isTemp(O,_), not isTemp(V,_),not removeRegulator(N,V,_). | ||
pos(regulator(O,V),t):- repair_i, regulator(N,V), function(N,W,_), isTemp(W,_),isFunction(W,O), not isTemp(O,_), not isTemp(V,_),not removeRegulator(N,V,_). | ||
|
||
|
||
|
||
repaired(N,V,t):- repair(regulator(O,V),_),regulator(N,V), function(N,W,_), isTemp(W,_),isFunction(W,O), not isTemp(O,_). | ||
|
||
%Negate regulators | ||
repaired(N,V,t):-repair(regulator(O,V),_),regulator(N,V),function(N,O,_). | ||
|
||
%Check if it is possible to apply it | ||
functionNot(temporary(regulator(N,V)),temporary(regulator(N,V)),t):-repaired(N,V,_), not functionNot(N,_,_). | ||
vertex(temporary(regulator(N,V)),t):-repaired(N,V,_), not functionNot(N,_,_). | ||
edge(temporary(regulator(N,V)),O,t):- repaired(N,V,_),function(N,O,_), not functionNot(N,_,_). | ||
edge(V,temporary(regulator(N,V)),t):- repaired(N,V,_), not functionNot(N,_,_). | ||
repair_functionNot(N,V,t):-functionNot(N,V,_), repaired(N,W,_),regulator(N,W). | ||
{ repair(R,t) : pos(R,t) }. | ||
|
||
|
||
|
||
%Test | ||
:-visit(P,V,TS,t), visit(P,V,TS-1,T),T>t,timeStep(TS),timeStep(TS-1). | ||
:-visit(P,V,TS,t), not visit(P,V,TS-1,_),timeStep(TS),timeStep(TS-1). | ||
:-visit(P,V,TS,t),visit(P,V,T,t),T!=TS. | ||
:-visit(P,V,TS,t),visit(P,W,TS,t),V!=W. | ||
:-visit(P,V,TS,t),visit(P,W,T,t),V!=W,T!=TS. | ||
:-visit(P,_,TS,t-1),visit(P,_,0,t),TS!=0. | ||
:-visit(P,V,TS,t-1),visit(P,W,T,t),TS!=0,T!=0,V!=W,vlabel(P,V,S,TS),vlabel(P,V,S,TS+1). | ||
:-not consistentFunction(P,O,t),visit(P,O,T,t), not input(P,O),T!=0. | ||
:-not consistentFunction(P,O,t),vertex(O,T),T!=0,exp(P). | ||
#program check(t). | ||
:-query(t),not visit(_,V,TI,_),goal(V,TI). | ||
%:-query(t),t<T,max(T). | ||
#show visit/4. | ||
#show repair/2. | ||
#minimize { 1, R,T:repair(R,T) }. |
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,33 @@ | ||
% Configure repairs operations. | ||
% Multiple repairs operations are obtained by combining the values in alphabetical order | ||
% Possible values include: | ||
% 'e' : remove edges | ||
% 'g' : flip gate | ||
% 'i' : negate regulator | ||
|
||
repair_e :- repair == e. | ||
repair_e :- repair == eg. | ||
repair_e :- repair == ei. | ||
repair_e :- repair == egi. | ||
repair_e :- repair == "e". | ||
repair_e :- repair == "eg". | ||
repair_e :- repair == "ei". | ||
repair_e :- repair == "egi". | ||
|
||
repair_g :- repair == g. | ||
repair_g :- repair == eg. | ||
repair_g :- repair == gi. | ||
repair_g :- repair == egi. | ||
repair_g :- repair == "g". | ||
repair_g :- repair == "eg". | ||
repair_g :- repair == "gi". | ||
repair_g :- repair == "egi". | ||
|
||
repair_i :- repair == i. | ||
repair_i :- repair == ei. | ||
repair_i :- repair == gi. | ||
repair_i :- repair == egi. | ||
repair_i :- repair == "i". | ||
repair_i :- repair == "ei". | ||
repair_i :- repair == "gi". | ||
repair_i :- repair == "egi". |
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,82 @@ | ||
#program base. | ||
|
||
% Configure repairs. | ||
% Multiple repairs by combining the values in alphabetical order to | ||
% Possible values include: | ||
% 'e' : remove edges | ||
% 'g' : flip gate | ||
% 'n' : nand and nor | ||
% 'i' : negate input of functions | ||
|
||
t_a :- time == asynchronous. | ||
t_s :- time == synchronous. | ||
t_a :- time == "asynchronous". | ||
t_s :- time == "synchronous". | ||
|
||
repair_e :- repair == e. | ||
repair_e :- repair == eg. | ||
repair_e :- repair == ei. | ||
repair_e :- repair == en. | ||
repair_e :- repair == egi. | ||
repair_e :- repair == egn. | ||
repair_e :- repair == ein. | ||
repair_e :- repair == egin. | ||
repair_e :- repair == "e". | ||
repair_e :- repair == "eg". | ||
repair_e :- repair == "ei". | ||
repair_e :- repair == "en". | ||
repair_e :- repair == "egi". | ||
repair_e :- repair == "egn". | ||
repair_e :- repair == "ein". | ||
repair_e :- repair == "egin". | ||
|
||
repair_g :- repair == g. | ||
repair_g :- repair == eg. | ||
repair_g :- repair == gi. | ||
repair_g :- repair == gn. | ||
repair_g :- repair == egi. | ||
repair_g :- repair == egn. | ||
repair_g :- repair == gin. | ||
repair_g :- repair == egin. | ||
repair_g :- repair == "g". | ||
repair_g :- repair == "eg". | ||
repair_g :- repair == "gi". | ||
repair_g :- repair == "gn". | ||
repair_g :- repair == "gin". | ||
repair_g :- repair == "egi". | ||
repair_g :- repair == "egn". | ||
repair_g :- repair == "gin". | ||
|
||
repair_i :- repair == i. | ||
repair_i :- repair == ei. | ||
repair_i :- repair == gi. | ||
repair_i :- repair == in. | ||
repair_i :- repair == egi. | ||
repair_i :- repair == ein. | ||
repair_i :- repair == gin. | ||
repair_i :- repair == egin. | ||
repair_i :- repair == "i". | ||
repair_i :- repair == "ei". | ||
repair_i :- repair == "gi". | ||
repair_i :- repair == "in". | ||
repair_i :- repair == "egi". | ||
repair_i :- repair == "ein". | ||
repair_i :- repair == "gin". | ||
repair_i :- repair == "egin". | ||
|
||
repair_n :- repair == n. | ||
repair_n :- repair == en. | ||
repair_n :- repair == gn. | ||
repair_n :- repair == in. | ||
repair_n :- repair == egn. | ||
repair_n :- repair == ein. | ||
repair_n :- repair == gin. | ||
repair_n :- repair == egin. | ||
repair_n :- repair == "n". | ||
repair_n :- repair == "en". | ||
repair_n :- repair == "gn". | ||
repair_n :- repair == "in". | ||
repair_n :- repair == "egn". | ||
repair_n :- repair == "ein". | ||
repair_n :- repair == "gin". | ||
repair_n :- repair == "egin". |
Oops, something went wrong.