Skip to content

Commit

Permalink
XP for additional value selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
augustindelecluse committed Apr 12, 2024
1 parent 2e8a977 commit 50a9038
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 35 deletions.
17 changes: 11 additions & 6 deletions scripts/run_xp_jobshop_with_attribution_small.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@ commitId=$(git rev-parse HEAD)
outFileOpt="results/jobshop/jobshop-opt-${commitId}-${currentDate}.csv" # filename of the results (with the date at the end of the file)

#valSel,Best,freqBest,PhaseSaving
declare -a valueSelection=("GREEDY,None,1,false"
"MIN,None,1,false"
"MIN,Best,1,false"
"MIN,BestSubset,1,false"
"MIN,ReverseBest,1,false"
"MIN,ReverseBestSubset,1,false") # each value selection to try
#declare -a valueSelection=("GREEDY,None,1,false"
#"MIN,None,1,false"
#"MIN,Best,1,false"
#"MIN,BestSubset,1,false"
#"MIN,ReverseBest,1,false"
#"MIN,ReverseBestSubset,1,false") # each value selection to try
declare -a valueSelection=("MAX,None,1,false"
"MED,None,1,false"
"RAND,None,1,false"
"MIN,BestSubsetInf,1,false"
"MIN,BestInf,1,false") # each value selection to try
timeout="00h30m00s" # timeout in seconds
iter=1 # number of iterations to account for randomness

Expand Down
17 changes: 11 additions & 6 deletions scripts/run_xp_qap_with_attribution.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@ commitId=$(git rev-parse HEAD)
outFileOpt="results/qap/qap-opt-${commitId}-${currentDate}.csv" # filename of the results (with the date at the end of the file)

#valSel,Best,freqBest,PhaseSaving
declare -a valueSelection=("GREEDY,None,1,false"
"MIN,None,1,false"
"MIN,Best,1,false"
"MIN,BestSubset,1,false"
"MIN,ReverseBest,1,false"
"MIN,ReverseBestSubset,1,false") # each value selection to try
#declare -a valueSelection=("GREEDY,None,1,false"
#"MIN,None,1,false"
#"MIN,Best,1,false"
#"MIN,BestSubset,1,false"
#"MIN,ReverseBest,1,false"
#"MIN,ReverseBestSubset,1,false") # each value selection to try
declare -a valueSelection=("MAX,None,1,false"
"MED,None,1,false"
"RAND,None,1,false"
"MIN,BestSubsetInf,1,false"
"MIN,BestInf,1,false") # each value selection to try
timeout="00h30m00s" # timeout in seconds
iter=1 # number of iterations to account for randomness

Expand Down
17 changes: 11 additions & 6 deletions scripts/run_xp_tsp_with_attribution.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@ commitId=$(git rev-parse HEAD)
outFileOpt="results/tsp/tsp-opt-${commitId}-${currentDate}.csv" # filename of the results (with the date at the end of the file)

#valSel,Best,freqBest,PhaseSaving
declare -a valueSelection=("GREEDY,None,1,false"
"MIN,None,1,false"
"MIN,Best,1,false"
"MIN,BestSubset,1,false"
"MIN,ReverseBest,1,false"
"MIN,ReverseBestSubset,1,false") # each value selection to try
#declare -a valueSelection=("GREEDY,None,1,false"
#"MIN,None,1,false"
#"MIN,Best,1,false"
#"MIN,BestSubset,1,false"
#"MIN,ReverseBest,1,false"
#"MIN,ReverseBestSubset,1,false") # each value selection to try
declare -a valueSelection=("MAX,None,1,false"
"MED,None,1,false"
"RAND,None,1,false"
"MIN,BestSubsetInf,1,false"
"MIN,BestInf,1,false") # each value selection to try
timeout="00h30m00s" # timeout in seconds
iter=1 # number of iterations to account for randomness

Expand Down
8 changes: 8 additions & 0 deletions scripts/run_xp_with_attribution.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
echo "running jobshop"
scripts/run_xp_jobshop_with_attribution_small.sh
echo "running qap"
scripts/run_xp_qap_with_attribution.sh
echo "running tsp"
scripts/run_xp_tsp_with_attribution.sh
echo "running xcsp"
scripts/run_xp_xcsp_with_attribution.sh
15 changes: 10 additions & 5 deletions scripts/run_xp_xcsp_with_attribution.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ commitId=$(git rev-parse HEAD)
outFileOpt="results/xcsp/xcsp-opt-${commitId}-${currentDate}.csv" # filename of the results (with the date at the end of the file)

#valSel,Best,freqBest,PhaseSaving
declare -a valueSelection=("MIN,None,1,false"
"MIN,Best,1,false"
"MIN,BestSubset,1,false"
"MIN,ReverseBest,1,false"
"MIN,ReverseBestSubset,1,false") # each value selection to try
#declare -a valueSelection=("MIN,None,1,false"
#"MIN,Best,1,false"
#"MIN,BestSubset,1,false"
#"MIN,ReverseBest,1,false"
#"MIN,ReverseBestSubset,1,false") # each value selection to try
declare -a valueSelection=("MAX,None,1,false"
"MED,None,1,false"
"RAND,None,1,false"
"MIN,BestSubsetInf,1,false"
"MIN,BestInf,1,false") # each value selection to try
timeout="00h30m00s" # timeout in seconds
iter=1 # number of iterations to account for randomness

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.chocosolver.solver.Model;
import org.chocosolver.solver.Solver;
import org.chocosolver.solver.search.restart.*;
import org.chocosolver.solver.search.strategy.assignments.DecisionOperatorFactory;
import org.chocosolver.solver.search.strategy.selectors.values.*;
import org.chocosolver.solver.search.strategy.selectors.variables.*;
import org.chocosolver.solver.search.strategy.strategy.AbstractStrategy;
Expand Down Expand Up @@ -100,7 +101,9 @@ enum BestSelection {
REVERSEBEST,
REVERSEBESTSUBSET,
REVERSEBESTMANUAL,
NONE
NONE,
BESTINF,
BESTSUBSETINF
}

/**
Expand Down Expand Up @@ -420,6 +423,12 @@ public Function<Model, IntValueSelector> make() {
case NONE:
fn1 = fn0;
break;
case BESTINF:
fn1 = m -> new IntDomainBest(Integer.MAX_VALUE, fn0.apply(m), v -> m.getSolver().getRestartCount() % bestFreq == 0, DecisionOperatorFactory.makeIntEq(), (k, v) -> false);
break;
case BESTSUBSETINF:
fn1 = m -> new IntDomainBestSubset(Integer.MAX_VALUE, fn0.apply(m), v -> m.getSolver().getRestartCount() % bestFreq == 0, DecisionOperatorFactory.makeIntEq(), (k, v) -> false, true);
break;
}
final Function<Model, IntValueSelector> fn2;
if (last) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import org.chocosolver.solver.search.strategy.assignments.DecisionOperatorFactory;
import org.chocosolver.solver.variables.IntVar;

import java.util.ArrayList;
import java.util.List;
import java.util.function.BiPredicate;
import java.util.function.Function;

Expand Down Expand Up @@ -44,8 +46,7 @@ public class IntDomainBestPruning implements IntValueSelector {

private final Function<IntVar, Boolean> trigger;
protected boolean pruning; // TODO pruning activation seems to prevent the triggering of some constraints
protected final int[] invalidValuesRemoved;
protected int nInvalidValuesRemoved = 0;
protected final List<Integer> invalidValuesRemoved;

/**
* Create a value selector that returns the best value wrt to the objective to optimize.
Expand Down Expand Up @@ -75,7 +76,7 @@ public IntDomainBestPruning(int maxdom, IntValueSelector intValueSelector, Funct
this.fallbackValueSelector = intValueSelector;
this.trigger = trigger;
this.pruning = pruning;
invalidValuesRemoved = new int[maxdom];
invalidValuesRemoved = new ArrayList<>();
}

/**
Expand Down Expand Up @@ -160,7 +161,7 @@ public int selectValue(IntVar var) throws ContradictionException {
return fallbackValueSelector.selectValue(var);
}
assert var.getModel().getObjective() != null;
nInvalidValuesRemoved = 0;
invalidValuesRemoved.clear();
int bestV;

if (var.getModel().getResolutionPolicy() != ResolutionPolicy.SATISFACTION) {
Expand Down Expand Up @@ -191,9 +192,8 @@ public int selectValue(IntVar var) throws ContradictionException {
bestV = lbB < ubB ? var.getLB() : var.getUB();
}
}
if (pruning && nInvalidValuesRemoved > 0) {
for (int i = 0 ; i < nInvalidValuesRemoved ; i++) {
int val = invalidValuesRemoved[i];
if (pruning && !invalidValuesRemoved.isEmpty()) {
for (int val: invalidValuesRemoved) {
dop.unapply(var, val, Cause.Null);
}
// the left branch will be x = v and the right branch x != v
Expand Down Expand Up @@ -226,7 +226,7 @@ protected int bound(IntVar var, int val, boolean removeIfInvalid) throws Contrad
if (pruning && !valid && removeIfInvalid) {
// removes the value if the operation failed
//dop.unapply(var, val, Cause.Null);
invalidValuesRemoved[nInvalidValuesRemoved++] = val;
invalidValuesRemoved.add(val);
}
return cost;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public int selectValue(IntVar var) throws ContradictionException {
if (objectiveReached) {
value = super.selectValue(var);
} else {
nInvalidValuesRemoved = 0;
invalidValuesRemoved.clear();
value = var.getLB(); // the objective will not change by modifying this variable
}
} catch (ContradictionException cex) {
Expand All @@ -79,8 +79,7 @@ public int selectValue(IntVar var) throws ContradictionException {
// reactivate the propagators
model.getEnvironment().worldPop();
// removes the values that were detected as invalid
for (int idx = 0 ; idx < nInvalidValuesRemoved ; idx++) {
int val = invalidValuesRemoved[idx];
for (int val: invalidValuesRemoved) {
dop.unapply(var, val, Cause.Null);
}
if (var.getDomainSize() <= 2) {
Expand Down

0 comments on commit 50a9038

Please sign in to comment.