Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Adding ForkSplit
  • Loading branch information
Tony authored and Tony committed Dec 8, 2015
1 parent 03c63b1 commit 915e5cc
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 17 deletions.
2 changes: 1 addition & 1 deletion jOptCSRecover/src/jopt/csp/example/api/StartHere.java
Expand Up @@ -46,7 +46,7 @@ public class StartHere {
// create the necessary 'variables'
CspIntVariable xVar = varFactory.intVar("x", 1, 4); // x = 1..4
CspIntVariable yVar = varFactory.intVar("y", 1, 3); // y = 1..3
CspIntVariable zVar = varFactory.intVar("z", 1, 12); // z = 1..12
CspIntVariable zVar = varFactory.intVar("z", 1, 6); // z = 1..12

// create the x * y <= z 'constraint'
CspConstraint constraint = xVar.multiply(yVar).leq(zVar);
Expand Down
62 changes: 62 additions & 0 deletions jOptJSRecover/src/jopt/js/spi/graph/arc/ForkSplit.java
@@ -0,0 +1,62 @@
package jopt.js.spi.graph.arc;

import java.util.concurrent.RecursiveAction;

import jopt.js.spi.graph.node.ResourceNode;

public class ForkSplit extends RecursiveAction {
/**
*
*/
//private static final long serialVersionUID = 40260316212684492L;
private int[] target_ID;
private ResourceNode[] targets;
private int start;
private int end;
private ResourceNode[] main_targets;


// Constructor will just take the inputted values and set them to the
//private member variable
public ForkSplit(int _start, int _end, ResourceNode[] _targets, int[] _target_ID, ResourceNode[] _main_targets){
this.start = _start;
this.end = _end;
this.target_ID = _target_ID;
this.targets = _targets;
this.main_targets = _main_targets;
}

@Override
// This function recursively forks the targets until they are separate.
// Then once they are all of them are computed at the same time.
protected void compute() {
if (end - start == 1){ // if each target has been forked then compute.
compute_directly();
}
else{ // recursively split that task into two until each targets is separate.
invokeAll(new ForkSplit(this.start,(this.end+this.start)/2,this.targets,this.target_ID, this.main_targets),
new ForkSplit((this.end+this.start)/2,this.end,this.targets,this.target_ID, this.main_targets));
}


}

// This method will run the for loop once each targets is forked
private void compute_directly(){
for (int i = 0; i < targets.length; i++){
if (target_ID[start] == targets[i].getID()){
main_targets[start] = targets[i];
break;
}
}


}


// This will return the targets to be saved in ForwardCheckArc.java
public ResourceNode[] get_main_targets(){
return this.main_targets;
}

}
21 changes: 14 additions & 7 deletions jOptJSRecover/src/jopt/js/spi/graph/arc/ForwardCheckArc.java
@@ -1,6 +1,7 @@
package jopt.js.spi.graph.arc;

import java.util.Arrays;
import java.util.concurrent.ForkJoinPool;

import jopt.csp.spi.arcalgorithm.graph.arc.Arc;
import jopt.csp.spi.arcalgorithm.graph.arc.SchedulerArc;
Expand Down Expand Up @@ -38,14 +39,20 @@ public class ForwardCheckArc extends SchedulerArc {
this.targets = new ResourceNode[targets.length];

//This will ensure that resources are ordered for fast easy access later
for (int i=0; i<targetIDs.length; i++) {
for (int j=0; j<targets.length; j++) {
if (targetIDs[i] == targets[j].getID()) {
this.targets[i] = targets[j];
break;
/*for (int i=0; i<targetIDs.length; i++) {
for (int j=0; j<targets.length; j++) {
if (targetIDs[i] == targets[j].getID()) {
this.targets[i] = targets[j];
break;
}
}
}
}
}*/

ForkSplit target_loop = new ForkSplit(0, targetIDs.length,targets,targetIDs,this.targets);
ForkJoinPool target_pool = new ForkJoinPool();
target_pool.invoke(target_loop);
this.targets = target_loop.get_main_targets(); // Will grab the targets object from forking
//and add it to the one here.
this.operationID = operationID;
}

Expand Down
23 changes: 14 additions & 9 deletions jOptJSRecover/src/jopt/js/spi/graph/arc/ForwardCheckReflexArc.java
@@ -1,6 +1,7 @@
package jopt.js.spi.graph.arc;

import java.util.Arrays;
import java.util.concurrent.ForkJoinPool;

import jopt.csp.spi.arcalgorithm.graph.arc.Arc;
import jopt.csp.spi.arcalgorithm.graph.arc.SchedulerArc;
Expand All @@ -10,7 +11,6 @@ import jopt.csp.util.IntIntervalSet;
import jopt.csp.variable.PropagationFailureException;
import jopt.js.spi.graph.node.ActivityNode;
import jopt.js.spi.graph.node.ResourceNode;

/**
* Arc to enforce and maintain consistency between resources and activities
*
Expand Down Expand Up @@ -38,14 +38,19 @@ public class ForwardCheckReflexArc extends SchedulerArc {
this.sources= new ResourceNode[sources.length];

//This will ensure that resources are ordered for fast and easy access later
for (int i=0; i<sourceIDs.length; i++) {
for (int j=0; j<sources.length; j++) {
if (sourceIDs[i] == sources[j].getID()) {
this.sources[i] = sources[j];
break;
}
}
}
/* for (int i=0; i<sourceIDs.length; i++) {
for (int j=0; j<sources.length; j++) {
if (sourceIDs[i] == sources[j].getID()) {
this.sources[i] = sources[j];
break;
}
}
} */

ForkSplit source_loop = new ForkSplit(0,sourceIDs.length,sources,sourceIDs, this.sources);
ForkJoinPool source_pool = new ForkJoinPool();
source_pool.invoke(source_loop);
this.sources = source_loop.get_main_targets();
this.operationID = operationID;
}

Expand Down

0 comments on commit 915e5cc

Please sign in to comment.