Commit acec6841 authored by Iran's avatar Iran
Browse files

some comments added

parent ecfdb225
......@@ -21,6 +21,8 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************************************/
package oru.smarter;
import java.util.Arrays;
import org.metacsp.booleanSAT.BooleanSatisfiabilitySolver;
import org.metacsp.booleanSAT.BooleanVariable;
import org.metacsp.framework.Constraint;
......@@ -29,6 +31,7 @@ import org.metacsp.framework.ValueChoiceFunction;
import org.metacsp.framework.ValueOrderingH;
import org.metacsp.framework.VariableOrderingH;
import org.metacsp.meta.symbolsAndTime.ReusableResource;
import org.metacsp.meta.symbolsAndTime.Schedulable.PEAKCOLLECTION;
import org.metacsp.meta.symbolsAndTime.Scheduler;
import org.metacsp.multi.activity.SymbolicVariableActivity;
import org.metacsp.multi.activity.ActivityNetworkSolver;
......@@ -47,17 +50,28 @@ public class TestReusableResourceScheduler {
public static void main(String[] args) {
final Scheduler metaSolver = new Scheduler(0,600,0);
final ActivityNetworkSolver groundSolver = (ActivityNetworkSolver)metaSolver.getConstraintSolvers()[0];
final Scheduler scheduler = new Scheduler(0,600,0);
final ActivityNetworkSolver temporalActivitySolver = (ActivityNetworkSolver)scheduler.getConstraintSolvers()[0];
final SymbolicVariableActivity one = (SymbolicVariableActivity)groundSolver.createVariable("Robot 1");
final SymbolicVariableActivity one = (SymbolicVariableActivity)temporalActivitySolver.createVariable("Robot 1");
final SymbolicVariableActivity two = (SymbolicVariableActivity)temporalActivitySolver.createVariable("Robot 2");
final SymbolicVariableActivity three = (SymbolicVariableActivity)temporalActivitySolver.createVariable("Robot 3");
//introducing reusable resource with capacity 4:
//ReusableResource rr1 = new ReusableResource(varOH, valOH, 4);
ReusableResource rr1 = new ReusableResource(null, null, 4);
rr1.setUsage(one,two,three);
scheduler.addMetaConstraint(rr1);
rr1.setPeakCollectionStrategy(PEAKCOLLECTION.COMPLETE);
//The activities use the resource in the following amounts:
one.setSymbolicDomain("2");
final SymbolicVariableActivity two = (SymbolicVariableActivity)groundSolver.createVariable("Robot 2");
two.setSymbolicDomain("1");
final SymbolicVariableActivity three = (SymbolicVariableActivity)groundSolver.createVariable("Robot 3");
two.setSymbolicDomain("2");
three.setSymbolicDomain("3");
//DURATIONS
//Activities have DURATIONS:
//(note: these are unary constraints, which means that each constraint is an edge from an activity to itself)
AllenIntervalConstraint dur1 = new AllenIntervalConstraint(AllenIntervalConstraint.Type.Duration, new Bounds(35, 55));
dur1.setFrom(one);
dur1.setTo(one);
......@@ -68,66 +82,45 @@ public class TestReusableResourceScheduler {
dur3.setFrom(three);
dur3.setTo(three);
//PRECEDENCES
//There are PRECEDENCES between activities:
//(note: these are binary constraints, which means that each constraint is an edge from an activity to another activity)
AllenIntervalConstraint con1 = new AllenIntervalConstraint(AllenIntervalConstraint.Type.Before, Type.Before.getDefaultBounds());
//no conflict: two before three
//two conflicts: two before one
con1.setFrom(one);
con1.setTo(two);
//groundSolver.addConstraint(con1);
//temporalActivitySolver.addConstraint(con1);
//Add the constraints
Constraint[] cons = new Constraint[]{dur1,dur2,dur3};
groundSolver.addConstraints(cons);
//Most critical conflict is the one with most activities (largest peak)
VariableOrderingH varOH = new VariableOrderingH() {
@Override
public int compare(ConstraintNetwork arg0, ConstraintNetwork arg1) {
return arg1.getVariables().length - arg0.getVariables().length;
}
@Override
public void collectData(ConstraintNetwork[] allMetaVariables) {
temporalActivitySolver.addConstraints(dur1,dur2,dur3);
}
};
//Add value ordering heuristic
ValueOrderingH valOH = new ValueOrderingH() {
@Override
public int compare(ConstraintNetwork o1, ConstraintNetwork o2) {
return 0;
}
};
//introducing reusable resource with capacity 4
ReusableResource rr1 = new ReusableResource(varOH, valOH, 4);
rr1.setUsage(one,two,three);
metaSolver.addMetaConstraint(rr1);
//Visualization
final TimelinePublisher tp = new TimelinePublisher(groundSolver.getConstraintNetwork(), "Robot 1", "Robot 2", "Robot 3");
final TimelinePublisher tp = new TimelinePublisher(temporalActivitySolver.getConstraintNetwork(), "Robot 1", "Robot 2", "Robot 3");
TimelineVisualizer viz = new TimelineVisualizer(tp);
tp.publish(true, true);
//This callback is executed when the user clicks on the button in the UI
Callback cb = new Callback() {
@Override
public void performOperation() {
metaSolver.backtrack();
//This makes the scheduler search for peak-leveling constraints
//(i.e., solves the scheduling problem)
scheduler.backtrack();
tp.publish(true, true);
metaSolver.draw();
scheduler.draw();
//Shows the resolving constraints that were computed
for (ConstraintNetwork cn : scheduler.getAddedResolvers()) {
System.out.println("Resolver added: " + Arrays.toString(cn.getConstraints()));
}
}
};
ConstraintNetwork cn = metaSolver.getConstraintNetworksFromSolverHierarchy(APSPSolver.class)[0];
ConstraintNetwork cn = scheduler.getConstraintNetworksFromSolverHierarchy(APSPSolver.class)[0];
ConstraintNetwork.draw(cn, "APSPSolver (Floyd Warshall)", cb);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment