// // Slack-Based Heuristics for Constraint Satisfaction Scheduling // Stephen F. Smith and Cheng-Chung Cheng // Proceedings AAAI-93 // import org.chocosolver.solver.variables.IntVar; import org.chocosolver.solver.search.strategy.selectors.values.IntValueSelector; import java.util.*; public class FuzzyMinSlackValue implements IntValueSelector { Random gen; double p; // probability that we accept heuristic advice FuzzyMinSlackValue(double p){ super(); gen = new Random(); this.p = p; } @Override public int selectValue(IntVar v){ if (gen.nextDouble() <= p){ Decision dec = (Decision) v; int slack_0 = slack(dec.op_i.start,dec.op_i.duration,dec.op_j.start,dec.op_j.duration); int slack_1 = slack(dec.op_j.start,dec.op_j.duration,dec.op_i.start,dec.op_i.duration); if (slack_0 > slack_1) return 1; else return 0; } else if (gen.nextDouble() < 0.5) return 0; else return 1; } // // decision = 0 -> op_i before op_j // decision = 1 -> op_j before op_i // private int slack(IntVar op_i,int d_i,IntVar op_j,int d_j){ return op_j.getUB() - Math.max(op_i.getLB() + d_i,op_j.getLB()); } // // slack if op_i before op_j // i.e. slack(op_i -> op_j) in S&C AAAI-93 parlance // // NOTE: we consider earliest and latest start times whereas S&C // consider earliest start and latest finish, but our calculations // are exactly the same // }