Predicates: Use constraints for addresses and backtracking for nodes
authorDaniel Schwyn <danielschwyn@gmail.com>
Mon, 22 May 2017 14:43:46 +0000 (16:43 +0200)
committerDaniel Schwyn <schwyda@student.ethz.ch>
Tue, 13 Jun 2017 12:21:38 +0000 (14:21 +0200)
Signed-off-by: Daniel Schwyn <schwyda@student.ethz.ch>

tools/sockeye2/decodingNet.pl
tools/sockeye2/decodingNet_naive.pl [new file with mode: 0644]

index 524e696..926548d 100644 (file)
@@ -8,21 +8,34 @@
 % Attn: Systems Group.
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-%% :- module(decodingNet,[resolve/2]).
-
 :- lib(ic).
 
-blockContains(block(Base, Limit),Addr) :-
-    %% between(Base,Limit,Addr).
-    Addr :: Base .. Limit.
+%% C constrains Addr to be in block
+inBlock(block(Base,Limit),Addr,C) :-
+    C = (Addr :: [Base..Limit]).
 
-blockListContains([B|Blocks],Addr) :-
-    blockContains(B,Addr);
-    blockListContains(Blocks,Addr).
+%% C constrains Addr to be in one of the blocks
+inBlockList(Blocks,Addr,C) :-
+    (
+        foreach(block(Base,Limit),Blocks),
+        fromto([],Prev,Next,Intervals)
+    do
+        Next = [Base..Limit|Prev]
+    ),
+    C = (Addr :: Intervals).
+    
+%% Extract blocks from map list
+blocksInMapList(Maps,Blocks) :-
+    (
+        foreach(map(Block,_,_),Maps),
+        fromto([],Prev,Next,Blocks)
+    do
+        Next = [Block|Prev]
+    ).
 
 mapsToName(map(SrcBlock,Dest,DestBase),Addr,Name) :-
     name(Dest,DestAddr) = Name,
-    blockContains(SrcBlock,Addr),
+    inBlock(SrcBlock,Addr,C),call(C),
     block(SrcBase,_) = SrcBlock,
     DestAddr #= Addr - SrcBase + DestBase.
 
@@ -30,22 +43,23 @@ listMapsToName([M|Maps],Addr,Name) :-
     mapsToName(M,Addr,Name);
     listMapsToName(Maps,Addr,Name).    
 
-accept(node(Accept,_,_),Addr) :-
-    blockListContains(Accept,Addr).
-
 translateMap(node(_,Translate,_),Addr,Name) :-
     listMapsToName(Translate,Addr,Name).
 
-translateOverlay(Node,Addr,Name) :-
-    not(accept(Node,Addr)),
-    not(translateMap(Node,Addr,Name)),
-    node(_,_,Overlay) = Node,
+translateOverlay(node(Accept,Translate,Overlay),Addr,Name) :-
+    inBlockList(Accept,Addr,C1),call(neg C1),
+    blocksInMapList(Translate,TBlocks),
+    inBlockList(TBlocks,Addr,C2),call(neg C2),
     Name = name(Overlay,Addr).
 
 translate(Node,Addr,Name) :-
     translateMap(Node,Addr,Name);
     translateOverlay(Node,Addr,Name).
 
+accept(node(Accept,_,_),Addr) :-
+    inBlockList(Accept,Addr,C),
+    call(C).
+
 acceptedName(Name) :-
     name(NodeId,Addr) = Name,
     net(NodeId,Node),
@@ -66,3 +80,14 @@ resolve(SrcName,DestName) :-
     ;   decodesTo(SrcName,DestName)
     ),
     acceptedName(DestName).
+
+findTargets(SrcName,DestName) :-
+    resolve(SrcName,DestName),
+    name(_,Addr) = DestName,
+    labeling([Addr]).
+    
+
+findOrigins(SrcName,DestName) :-
+    resolve(SrcName,DestName),
+    name(_,Addr) = SrcName,
+    labeling([Addr]).
diff --git a/tools/sockeye2/decodingNet_naive.pl b/tools/sockeye2/decodingNet_naive.pl
new file mode 100644 (file)
index 0000000..68e7c4e
--- /dev/null
@@ -0,0 +1,52 @@
+blockContains(block(Base, Limit),Addr) :-
+    between(Base,Limit,Addr).
+
+blockListContains([B|Blocks],Addr) :-
+    blockContains(B,Addr),!;
+    blockListContains(Blocks,Addr).
+
+mapsToName(map(SrcBlock,Dest,DestBase),Addr,Name) :-
+    name(Dest,DestAddr) = Name,
+    blockContains(SrcBlock,Addr),
+    block(SrcBase,_) = SrcBlock,
+    DestAddr is Addr - SrcBase + DestBase.
+
+listMapsToName([M|Maps],Addr,Name) :-
+    mapsToName(M,Addr,Name);
+    listMapsToName(Maps,Addr,Name).    
+
+accept(node(Accept,_,_),Addr) :-
+    blockListContains(Accept,Addr).
+
+translateMap(node(_,Translate,_),Addr,Name) :-
+    listMapsToName(Translate,Addr,Name).
+
+translateOverlay(node(_,_,Overlay),Addr,Name) :-
+    Name = name(Overlay,Addr).
+
+translate(Node,Addr,Name) :-
+    translateMap(Node,Addr,Name),!;
+    (   not(accept(Node,Addr))
+    ,   translateOverlay(Node,Addr,Name)
+    ).
+
+acceptedName(Name) :-
+    name(NodeId,Addr) = Name,
+    net(NodeId,Node),
+    accept(Node,Addr).
+
+decodeStep(name(NodeId,Addr),Name) :-
+    net(NodeId,Node),
+    translate(Node,Addr,Name).
+
+decodesTo(SrcName,DestName) :-
+    decodeStep(SrcName,Name),
+    (   DestName = Name,!
+    ;   decodesTo(Name,DestName)
+    ).
+
+resolve(SrcName,DestName) :-
+    (   DestName = SrcName
+    ;   decodesTo(SrcName,DestName)
+    ),
+    acceptedName(DestName).