forked from GreenSolver/green
-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
only OnlyConstantPropagation finished #54
Open
RPasch
wants to merge
74
commits into
wvisser:master
Choose a base branch
from
RPasch:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
74 commits
Select commit
Hold shift + click to select a range
052fb15
Update EnitreSuite.java
RPasch 12729eb
Update EntireSuite.java
RPasch e344201
Update SATCanonizerTest.java
RPasch 1668157
Update build.xml
RPasch 7c95328
Update EntireSuite.java
RPasch deb4580
Update EntireSuite.java
RPasch 266494f
Update SATCanonizerTest.java
RPasch 6b2e60d
Update SATCanonizerTest.java
RPasch 98777f8
Update EntireSuite.java
RPasch a94efc3
Update build.xml
RPasch fa09bee
Update EntireSuite.java
RPasch dd72785
Update build.xml
RPasch 3656b42
Update SATCanonizerTest.java
RPasch cf96b09
Update README.md
RPasch 49ee8fb
Update README.md
RPasch 6fc1e29
Update README.md
RPasch ccae141
Update README.md
RPasch 29a02eb
Update .travis.yml
RPasch d7f56ac
Update .travis.yml
RPasch 8ec138e
Update .travis.yml
RPasch 1f8a126
Update .travis.yml
RPasch 04c987a
Update .travis.yml
RPasch f732bed
Update .travis.yml
RPasch 796023c
Update .travis.yml
RPasch e9b94f1
Update Dockerfile
RPasch 5628345
Update build.xml
RPasch feff580
Update EntireSuite.java
RPasch 0634f87
out dated commit
RPasch 3ed7c53
some changes to constantPropogation
RPasch f0a798f
added a method or two
RPasch f60f821
another method
RPasch 3d19219
SATcanonizer....
RPasch 1c4fdaa
Post Visit nr1????
RPasch 1c1205b
it is propAgate not propogate...
RPasch 4702af9
Are you going to compile now?
RPasch dff6060
surely
RPasch 31b5bcc
Update EntireSuite.java
RPasch 62135f7
Update ConstantPropagation.java
RPasch 389dea8
Update build.xml
RPasch 3a38f66
Update ConstantPropagation.java
RPasch f7fe857
Update ConstantPropagation.java
RPasch 3ad590b
???
RPasch 65f29c5
Update SimplificationConstantPropogationTest.java
RPasch cd7f8da
Update ConstantPropagation.java
RPasch c959c35
Update and rename SimplificationConstantPropogationTest.java to Simpl…
RPasch 52b997c
Update and rename OnlyConstantPropogationTest.java to OnlyConstantPro…
RPasch a0d4f80
Add files via upload
RPasch ad22b19
Delete OnlyConstantPropagationTest.java
RPasch 172ddb7
Delete SimplificationConstantPropagationTest.java
RPasch 1fcbe43
Update and rename OnlyConstantPropogationTest.java to OnlyConstantPro…
RPasch 7f8f64c
Update and rename SimplificationConstantPropogationTest.java to Simpl…
RPasch 2936996
Update and rename SimplificationConstantPropagationTest.java to Simpl…
RPasch 9cbe87e
Update and rename OnlyConstantPropagationTest.java to OnlyConstantPro…
RPasch 1eac2d4
Update EntireSuite.java
RPasch 750039a
Update and rename ConstantPropagation.java to ConstantPropogation.java
RPasch fc61bd9
Update ConstantPropogation.java
RPasch f6431e5
Update ConstantPropogation.java
RPasch 7699108
Update ConstantPropogation.java
RPasch 086fcf9
Update ConstantPropogation.java
RPasch c655b15
Update ConstantPropogation.java
RPasch dcc7fcd
Update ConstantPropogation.java
RPasch 2c68f0c
Update ConstantPropogation.java
RPasch 9cc543d
Update ConstantPropogation.java
RPasch 3afa438
Update build.xml
RPasch 46f3cb9
Update ConstantPropogation.java
RPasch c2347db
Update build.xml
RPasch 5d0d4c4
Update ConstantPropogation.java
RPasch fb83f68
Update EntireSuite.java
RPasch cf851cf
Update EntireSuite.java
RPasch 72b7191
Update EntireSuite.java
RPasch d9d901f
Update ConstantPropogation.java
RPasch ea51c9c
Update ConstantPropogation.java
RPasch bee3ec9
Update ConstantPropogation.java
RPasch 5362d68
Update ConstantPropogation.java
RPasch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1,5 +1,14 @@ | ||
sudo: required | ||
|
||
language: java | ||
|
||
services: | ||
- docker | ||
|
||
before_install: | ||
- docker build -t carlad/sinatra . | ||
|
||
|
||
script: | ||
- ant; | ||
- ant test; | ||
- docker run carlad/sinatra /bin/sh -c "ant; ant test;" | ||
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
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
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
194 changes: 194 additions & 0 deletions
194
src/za/ac/sun/cs/green/service/simplify/ConstantPropogation.java
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,194 @@ | ||
package za.ac.sun.cs.green.service.simplify; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.SortedMap; | ||
import java.util.SortedSet; | ||
import java.util.Stack; | ||
import java.util.TreeMap; | ||
import java.util.TreeSet; | ||
import java.util.logging.Level; | ||
|
||
import za.ac.sun.cs.green.Instance; | ||
import za.ac.sun.cs.green.Green; | ||
import za.ac.sun.cs.green.expr.Expression; | ||
import za.ac.sun.cs.green.expr.Variable; | ||
import za.ac.sun.cs.green.expr.Visitor; | ||
import za.ac.sun.cs.green.expr.VisitorException; | ||
import za.ac.sun.cs.green.service.BasicService; | ||
import za.ac.sun.cs.green.util.Reporter; | ||
import za.ac.sun.cs.green.expr.Constant; | ||
import za.ac.sun.cs.green.expr.IntConstant; | ||
import za.ac.sun.cs.green.expr.IntVariable; | ||
import za.ac.sun.cs.green.expr.Operation; | ||
|
||
public class ConstantPropogation extends BasicService { | ||
|
||
|
||
private int invocations = 0; | ||
|
||
public ConstantPropogation(Green solver) { | ||
super(solver); | ||
} | ||
|
||
@Override | ||
public Set<Instance> processRequest(Instance instance) { | ||
@SuppressWarnings("unchecked") | ||
Set<Instance> result = (Set<Instance>) instance.getData(getClass()); | ||
if (result == null) { | ||
final Map<Variable, Variable> map = new HashMap<Variable, Variable>(); | ||
final Expression e = propagateConstants(instance.getFullExpression(), map); | ||
final Instance i = new Instance(getSolver(), instance.getSource(), null, e); | ||
final Instance f = new Instance(getSolver(), instance.getSource(), null , e); | ||
result = Collections.singleton(i); | ||
instance.setData(getClass(), result); | ||
} | ||
return result; | ||
} | ||
|
||
@Override | ||
public void report(Reporter reporter) { | ||
reporter.report(getClass().getSimpleName(), "invocations = " + invocations); | ||
} | ||
|
||
public Expression propagateConstants(Expression expr, Map<Variable, Variable> map) { | ||
try { | ||
log.log(Level.FINEST, "Before Constant Propagation: " + expr); | ||
invocations++; | ||
cPvisitor cPv = new cPvisitor(); | ||
cPvisitor cpVVtest = new cPvisitor(); | ||
expr.accept(cPv); | ||
Expression propTest; | ||
Expression prop = cPv.getExpression(); | ||
log.log(Level.FINEST, "After Constant Propagation: " + prop); | ||
return prop; | ||
} catch (VisitorException ex) { | ||
log.log(Level.SEVERE, "Something is not right.", ex); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
|
||
|
||
private static class cPvisitor extends Visitor { | ||
private Stack<Expression> stack; | ||
private Stack<Expression> stackyMcStackStack; | ||
private Map<IntVariable, IntConstant> Vmap; | ||
private Map<IntVariable , IntConstant> mappy; | ||
|
||
public cPvisitor() { | ||
stack = new Stack<Expression>(); | ||
stackyMcStackStack = new Stack<Expression>(); | ||
Vmap = new TreeMap<IntVariable, IntConstant>(); | ||
mappy = new TreeMap<IntVariable , IntConstant>(); | ||
} | ||
|
||
public Expression getExpression() { | ||
Expression ex = null; | ||
if(stack.isEmpty()){ | ||
return null; | ||
|
||
}else{ | ||
ex = stack.pop(); | ||
|
||
} | ||
return ex; | ||
} | ||
|
||
@Override | ||
public void postVisit(Constant cons) { | ||
if(cons instanceof IntConstant){ | ||
stack.push(cons); | ||
stackyMcStackStack.push(cons); | ||
} else { | ||
|
||
stack.clear(); | ||
stackyMcStackStack.clear(); | ||
} | ||
|
||
|
||
} | ||
|
||
@Override | ||
public void postVisit(Variable var) { | ||
if(var instanceof IntVariable){ | ||
stack.push(var); | ||
stackyMcStackStack.push(var); | ||
} else { | ||
stack.clear(); | ||
stackyMcStackStack.clear(); | ||
} | ||
|
||
|
||
} | ||
|
||
@Override | ||
public void postVisit(Operation operation) throws VisitorException { | ||
Operation.Operator op = operation.getOperator(); | ||
Operation.Operator nop = null; | ||
switch (op) { | ||
case EQ: | ||
nop = Operation.Operator.EQ; | ||
break; | ||
case NE: | ||
nop = Operation.Operator.NE; | ||
break; | ||
case LT: | ||
nop = Operation.Operator.GT; | ||
break; | ||
case LE: | ||
nop = Operation.Operator.GE; | ||
break; | ||
case GT: | ||
nop = Operation.Operator.LT; | ||
break; | ||
case GE: | ||
nop = Operation.Operator.LE; | ||
break; | ||
default: | ||
break; | ||
} | ||
if (nop != null) { | ||
if(stackyMcStackStack.size()>=2){ | ||
Expression rR = stackyMcStackStack.pop(); | ||
Expression lL = stackyMcStackStack.pop(); | ||
if((lL instanceof IntVariable) && (rR instanceof IntConstant)){ | ||
mappy.put((IntVariable)lL ,(IntConstant) rR); | ||
}else if((rR instanceof IntVariable) && (lL instanceof IntConstant)){ | ||
mappy.put((IntVariable)rR,(IntConstant)lL); | ||
} | ||
} | ||
} | ||
|
||
|
||
if(stack.size()>=2){ | ||
Expression r = stack.pop(); | ||
Expression l = stack.pop(); | ||
Operation.Operator oper = op; | ||
if(oper.equals(Operation.Operator.EQ)){ | ||
if((l instanceof IntVariable) && (r instanceof IntConstant)){ | ||
Vmap.put((IntVariable)l ,(IntConstant) r); | ||
}else if((r instanceof IntVariable) && (l instanceof IntConstant)){ | ||
Vmap.put((IntVariable)r,(IntConstant)l); | ||
} | ||
stack.push(new Operation(oper,l,r)); | ||
} else if(!oper.equals(Operation.Operator.EQ)){ | ||
|
||
if (Vmap.containsKey(l)) { | ||
l = Vmap.get(l); | ||
} else if(Vmap.containsKey(r)){ | ||
r = Vmap.get(r); | ||
} | ||
stack.push(new Operation(oper , l , r)); | ||
} | ||
} | ||
} | ||
//return null; | ||
} | ||
|
||
} | ||
|
||
|
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
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
74 changes: 74 additions & 0 deletions
74
test/za/ac/sun/cs/green/service/simplify/OnlyConstantPropogationTest.java
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,74 @@ | ||
package za.ac.sun.cs.green.service.simplify; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import java.util.Arrays; | ||
import java.util.Properties; | ||
import java.util.SortedSet; | ||
import java.util.TreeSet; | ||
|
||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
import za.ac.sun.cs.green.Instance; | ||
import za.ac.sun.cs.green.Green; | ||
import za.ac.sun.cs.green.expr.Expression; | ||
import za.ac.sun.cs.green.expr.IntConstant; | ||
import za.ac.sun.cs.green.expr.IntVariable; | ||
import za.ac.sun.cs.green.expr.Operation; | ||
import za.ac.sun.cs.green.util.Configuration; | ||
|
||
public class OnlyConstantPropogationTest { | ||
|
||
public static Green solver; | ||
|
||
@BeforeClass | ||
public static void initialize() { | ||
solver = new Green(); | ||
Properties props = new Properties(); | ||
props.setProperty("green.services", "sat"); | ||
props.setProperty("green.service.sat", "(simplify sink)"); | ||
//props.setProperty("green.service.sat", "(canonize sink)"); | ||
props.setProperty("green.service.sat.simplify", | ||
"za.ac.sun.cs.green.service.simplify.ConstantPropogation"); | ||
//props.setProperty("green.service.sat.canonize", | ||
// "za.ac.sun.cs.green.service.canonizer.SATCanonizerService"); | ||
|
||
props.setProperty("green.service.sat.sink", | ||
"za.ac.sun.cs.green.service.sink.SinkService"); | ||
Configuration config = new Configuration(solver, props); | ||
config.configure(); | ||
} | ||
|
||
private void finalCheck(String observed, String expected) { | ||
assertEquals(expected, observed); | ||
} | ||
|
||
private void check(Expression expression, String expected) { | ||
Instance i = new Instance(solver, null, null, expression); | ||
Expression e = i.getExpression(); | ||
assertTrue(e.equals(expression)); | ||
assertEquals(expression.toString(), e.toString()); | ||
Object result = i.request("sat"); | ||
assertNotNull(result); | ||
assertEquals(Instance.class, result.getClass()); | ||
Instance j = (Instance) result; | ||
finalCheck(j.getExpression().toString(), expected); | ||
} | ||
|
||
@Test | ||
public void test00() { | ||
IntVariable x = new IntVariable("x", 0, 99); | ||
IntVariable y = new IntVariable("y", 0, 99); | ||
IntVariable z = new IntVariable("z", 0, 99); | ||
IntConstant c = new IntConstant(1); | ||
IntConstant c10 = new IntConstant(10); | ||
IntConstant c3 = new IntConstant(3); | ||
Operation o1 = new Operation(Operation.Operator.EQ, x, c); // o1 : x = 1 | ||
Operation o2 = new Operation(Operation.Operator.ADD, x, y); // o2 : (x + y) | ||
Operation o3 = new Operation(Operation.Operator.EQ, o2, c10); // o3 : x+y = 10 | ||
Operation o4 = new Operation(Operation.Operator.AND, o1, o3); // o4 : x = 1 && (x+y) = 10 | ||
check(o4, "(x==1)&&((1+y)==10)"); | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make use of the same coding convention adhered to in the original repo.