org.ggp.base.util.gdl.model.assignments.FunctionInfos Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of alloy-ggp-base Show documentation
Show all versions of alloy-ggp-base Show documentation
A modified version of the GGP-Base library for Alloy.
The newest version!
package org.ggp.base.util.gdl.model.assignments;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.ggp.base.util.gdl.GdlUtils;
import org.ggp.base.util.gdl.grammar.GdlSentence;
import org.ggp.base.util.gdl.grammar.GdlTerm;
import org.ggp.base.util.gdl.grammar.GdlVariable;
public class FunctionInfos {
public static Set getProducibleVars(FunctionInfo functionInfo, GdlSentence sentence) {
if (!functionInfo.getSentenceForm().matches(sentence)) {
throw new RuntimeException("Sentence "+sentence+" does not match constant form");
}
List tuple = GdlUtils.getTupleFromSentence(sentence);
List dependentSlots = functionInfo.getDependentSlots();
Set candidateVars = new HashSet();
//Variables that appear multiple times go into multipleVars
Set multipleVars = new HashSet();
//...which, of course, means we have to spot non-candidate vars
Set nonCandidateVars = new HashSet();
for(int i = 0; i < tuple.size(); i++) {
GdlTerm term = tuple.get(i);
if(term instanceof GdlVariable
&& !multipleVars.contains(term)) {
GdlVariable var = (GdlVariable) term;
if (candidateVars.contains(var)
|| nonCandidateVars.contains(var)) {
multipleVars.add(var);
candidateVars.remove(var);
} else if (dependentSlots.get(i)) {
candidateVars.add(var);
} else {
nonCandidateVars.add(var);
}
}
}
return candidateVars;
}
}