public void init(Solver solver) {
}
/** Neighbour selection */
public Neighbour selectNeighbour(Solution solution) {
Model model = solution.getModel();
if (iVarEn==null) {
iVarEn = new RandomEnumeration(model.variables(), iRandomOrder);
iVariable = (Variable)iVarEn.nextElement();
Vector v2 = new Vector(iVariable.values().size()+model.variables().size());
if (iAllowSwaps && iVariable instanceof Swapable)
v2.addAll(model.variables());
v2.addAll(iVariable.values());
iValEn = new RandomEnumeration(v2, iRandomOrder);
}
SimpleNeighbour n = null;
if (!iValEn.hasMoreElements()) {
if (!iVarEn.hasMoreElements()) {
iVarEn = new RandomEnumeration(model.variables(), iRandomOrder);
}
iVariable = (Variable)iVarEn.nextElement();
Vector v2 = new Vector(iVariable.values().size()+model.variables().size());
if (iAllowSwaps && iVariable instanceof Swapable)
v2.addAll(model.variables());
v2.addAll(iVariable.values());
iValEn = new RandomEnumeration(v2, iRandomOrder);
}
Object object = iValEn.nextElement();
if (object instanceof Variable) {
Variable anotherVariable = (Variable)ToolBox.random(model.variables());
if (iVariable.equals(anotherVariable)) return null;
return ((Swapable)iVariable).findSwap(anotherVariable);
} else {
Value value = (Value)object;
if (value.equals(iVariable.getAssignment())) return null;
Set conflicts = model.conflictValues(value);
double eval = iValueWeight * value.toDouble();
if (iVariable.getAssignment()!=null)
eval -= iValueWeight * iVariable.getAssignment().toDouble();
else
eval -= iConflictWeight;
eval += iConflictWeight * model.conflictValues(value).size();
return new ItcSimpleNeighbour(iVariable,value,eval);
}
}