Skip to content
Browse files

repair propnet edge case

  • Loading branch information...
1 parent 2710d2c commit cfb7eba0480d0ec54abd0e4d3ad7048f3f095e6a Daniel Erenrich committed May 21, 2012
View
12 src/util/propnet/architecture/PropNet.java
@@ -16,6 +16,7 @@
import util.gdl.grammar.GdlTerm;
import util.logging.GamerLogger;
import util.propnet.architecture.components.And;
+import util.propnet.architecture.components.Constant;
import util.propnet.architecture.components.Not;
import util.propnet.architecture.components.Or;
import util.propnet.architecture.components.Proposition;
@@ -157,6 +158,17 @@ public PropNet(List<Role> roles, Set<Component> components)
return legalInputMap;
}
+ public Set<Constant> getConstantComponents()
+ {
+ Set<Constant> constantProps = new HashSet<Constant>();
+ for(Component p : this.components) {
+ if(p instanceof Constant) {
+ constantProps.add((Constant) p);
+ }
+ }
+ return constantProps;
+ }
+
/**
* Getter method.
*
View
31 src/util/statemachine/implementation/propnet/PropNetStateMachine.java
@@ -157,7 +157,7 @@ public MachineState getNextState(MachineState state, List<Move> moves) throws Tr
for(GdlTerm t : terms) {
this.propNet.getInputPropositions().get(t).setValue(true);
}
- this.propogateTruth();
+ this.propogateTruth();
MachineState s = this.getStateFromBase();
for(Proposition p : propNet.getInputPropositions().values()) {
p.setValue(false);
@@ -189,24 +189,23 @@ public MachineState getNextState(MachineState state, List<Move> moves) throws Tr
HashSet<Component> components = new HashSet<Component>(propNet.getComponents());
// All of the propositions in the PropNet.
- List<Proposition> propositions = new ArrayList<Proposition>(propNet.getPropositions());
-
- // TODO: Compute the topological ordering.
+ List<Proposition> propositions = new ArrayList<Proposition>(propNet.getPropositions());
// Generate list of starting nodes
List<Proposition> start = new ArrayList<Proposition>();
start.addAll(propNet.getInputPropositions().values());
start.addAll(propNet.getBasePropositions().values());
start.add(propNet.getInitProposition());
-
- // Have we already added the Component to the ordering?
- Set<Component> used = new HashSet<Component>();
+ // Have we already added the Component to the ordering?
+ Set<Component> used = new HashSet<Component>();
Set<Component> frontier = new HashSet<Component>();
Set<Component> fringe;
+
for(Component s :start) {
frontier.addAll(s.getOutputs());
}
+ frontier.addAll(propNet.getConstantComponents());
used.addAll(start);
// Perform Depth first search of sorts
while(!frontier.isEmpty()){
@@ -215,6 +214,7 @@ public MachineState getNextState(MachineState state, List<Move> moves) throws Tr
fringe = new HashSet<Component>();
while(iter.hasNext()) {
Component c = iter.next();
+ // check if all parents are computed
boolean addMe = true;
for(Component parent:c.getInputs()) {
if(!used.contains(parent))
@@ -231,21 +231,11 @@ public MachineState getNextState(MachineState state, List<Move> moves) throws Tr
}
// Expand the frontier
- // baseProps are problematic. This is taken care of by not expanding transitions
- //newFringe.removeAll(baseProps);
fringe.removeAll(used);
- // System.out.println("Adding : "+fringe.size());
- // System.out.println("Frontier size: " + frontier.size());
- // System.out.println("Ordered : "+order.size()+" of " + (propositions.size()-start.size()));
frontier.addAll(fringe);
if(fringe.size()==0) {
- System.out.println("We have run out of options");
- propositions.removeAll(order);
- propositions.removeAll(start);
- System.out.println("The "+propositions.size()+" lost souls: "+propositions);
break;
}
-
}
return order;
}
@@ -269,12 +259,7 @@ private void propogateTruth(){
p.setValue(p.getSingleInput().getValue());
}
}
- private void injectState(MachineState state){
-
- for(Proposition p : propNet.getBasePropositions().values()) {
- p.setValue(false);
- }
-
+ private void injectState(MachineState state){
for(GdlSentence s : state.getContents()) {
propNet.getBasePropositions().get(s.toTerm()).setValue(true);
}

0 comments on commit cfb7eba

Please sign in to comment.
Something went wrong with that request. Please try again.