本文整理汇总了Java中org.cpsolver.ifs.heuristics.NeighbourSelection类的典型用法代码示例。如果您正苦于以下问题:Java NeighbourSelection类的具体用法?Java NeighbourSelection怎么用?Java NeighbourSelection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NeighbourSelection类属于org.cpsolver.ifs.heuristics包,在下文中一共展示了NeighbourSelection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: NeighbourSearch
import org.cpsolver.ifs.heuristics.NeighbourSelection; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public NeighbourSearch(DataProperties properties) {
iPhase = getClass().getSimpleName().replaceAll("(?<=[^A-Z])([A-Z])"," $1");
iLog = Logger.getLogger(getClass());
iRandomSelection = properties.getPropertyBoolean(getParameterBaseName() + ".Random", iRandomSelection);
iUpdatePoints = properties.getPropertyBoolean(getParameterBaseName() + ".Update", iUpdatePoints);
String neighbours = properties.getProperty(getParameterBaseName() + ".Neighbours",
RandomMove.class.getName() + ";" + RandomSwapMove.class.getName() + "@0.01;" + SuggestionMove.class.getName() + "@0.01");
neighbours += ";" + properties.getProperty(getParameterBaseName() + ".AdditionalNeighbours", "");
iNeighbours = new ArrayList<NeighbourSelector<V,T>>();
for (String neighbour: neighbours.split("\\;")) {
if (neighbour == null || neighbour.isEmpty()) continue;
try {
double bonus = 1.0;
if (neighbour.indexOf('@')>=0) {
bonus = Double.parseDouble(neighbour.substring(neighbour.indexOf('@') + 1));
neighbour = neighbour.substring(0, neighbour.indexOf('@'));
}
Class<NeighbourSelection<V, T>> clazz = (Class<NeighbourSelection<V, T>>)Class.forName(neighbour);
NeighbourSelection<V, T> selection = clazz.getConstructor(DataProperties.class).newInstance(properties);
addNeighbourSelection(selection, bonus);
} catch (Exception e) {
iLog.error("Unable to use " + neighbour + ": " + e.getMessage());
}
}
}
示例2: SimpleSearch
import org.cpsolver.ifs.heuristics.NeighbourSelection; //导入依赖的package包/类
/**
* Constructor
* @param properties problem configuration
* @throws Exception thrown when initialization fails (e.g., a given class is not found)
*/
public SimpleSearch(DataProperties properties) throws Exception {
String construction = properties.getProperty("Construction.Class");
if (construction != null) {
try {
@SuppressWarnings("unchecked")
Class<NeighbourSelection<V, T>> constructionClass = (Class<NeighbourSelection<V, T>>)Class.forName(properties.getProperty("Construction.Class"));
iCon = constructionClass.getConstructor(DataProperties.class).newInstance(properties);
iConstructionUntilComplete = properties.getPropertyBoolean("Construction.UntilComplete", iConstructionUntilComplete);
} catch (Exception e) {
iLog.error("Unable to use " + construction + ": " + e.getMessage());
}
}
iStd = new StandardNeighbourSelection<V, T>(properties);
iSA = new SimulatedAnnealing<V, T>(properties);
if (properties.getPropertyBoolean("Search.CountSteps", false))
iHC = new StepCountingHillClimber<V, T>(properties);
else
iHC = new HillClimber<V, T>(properties);
iGD = new GreatDeluge<V, T>(properties);
iUseGD = properties.getPropertyBoolean("Search.GreatDeluge", iUseGD);
}
示例3: ExamGreatDeluge
import org.cpsolver.ifs.heuristics.NeighbourSelection; //导入依赖的package包/类
/**
* Constructor. Following problem properties are considered:
* <ul>
* <li>GreatDeluge.CoolRate ... bound cooling rate (default 0.99999995)
* <li>GreatDeluge.UpperBoundRate ... bound upper bound relative to best
* solution ever found (default 1.05)
* <li>GreatDeluge.LowerBoundRate ... bound lower bound relative to best
* solution ever found (default 0.95)
* </ul>
*
* @param properties
* problem properties
*/
@SuppressWarnings("unchecked")
public ExamGreatDeluge(DataProperties properties) {
iCoolRate = properties.getPropertyDouble("GreatDeluge.CoolRate", iCoolRate);
iUpperBoundRate = properties.getPropertyDouble("GreatDeluge.UpperBoundRate", iUpperBoundRate);
iLowerBoundRate = properties.getPropertyDouble("GreatDeluge.LowerBoundRate", iLowerBoundRate);
String neighbours = properties.getProperty("GreatDeluge.Neighbours",
ExamRandomMove.class.getName() + ";" +
ExamRoomMove.class.getName() + ";" +
ExamTimeMove.class.getName());
neighbours += ";" + properties.getProperty("GreatDeluge.AdditionalNeighbours", "");
iNeighbours = new ArrayList<NeighbourSelection<Exam,ExamPlacement>>();
for (String neighbour: neighbours.split("\\;")) {
if (neighbour == null || neighbour.isEmpty()) continue;
try {
Class<NeighbourSelection<Exam, ExamPlacement>> clazz = (Class<NeighbourSelection<Exam, ExamPlacement>>)Class.forName(neighbour);
iNeighbours.add(clazz.getConstructor(DataProperties.class).newInstance(properties));
} catch (Exception e) {
sLog.error("Unable to use " + neighbour + ": " + e.getMessage());
}
}
}
示例4: ExamHillClimbing
import org.cpsolver.ifs.heuristics.NeighbourSelection; //导入依赖的package包/类
/**
* Constructor
*
* @param properties
* problem properties (use HillClimber.MaxIdle to set maximum
* number of idle iterations)
* @param name solver search phase name
*/
@SuppressWarnings("unchecked")
public ExamHillClimbing(DataProperties properties, String name) {
iMaxIdleIters = properties.getPropertyInt("HillClimber.MaxIdle", iMaxIdleIters);
String neighbours = properties.getProperty("HillClimber.Neighbours",
ExamRandomMove.class.getName() + ";" +
ExamRoomMove.class.getName() + ";" +
ExamTimeMove.class.getName());
neighbours += ";" + properties.getProperty("HillClimber.AdditionalNeighbours", "");
iNeighbours = new ArrayList<NeighbourSelection<Exam,ExamPlacement>>();
for (String neighbour: neighbours.split("\\;")) {
if (neighbour == null || neighbour.isEmpty()) continue;
try {
Class<NeighbourSelection<Exam, ExamPlacement>> clazz = (Class<NeighbourSelection<Exam, ExamPlacement>>)Class.forName(neighbour);
iNeighbours.add(clazz.getConstructor(DataProperties.class).newInstance(properties));
} catch (Exception e) {
sLog.error("Unable to use " + neighbour + ": " + e.getMessage());
}
}
iName = name;
}
示例5: selectNeighbour
import org.cpsolver.ifs.heuristics.NeighbourSelection; //导入依赖的package包/类
/**
* Select one of the given neighbourhoods randomly, select neighbour, return
* it if its value is below or equal to zero (continue with the next
* selection otherwise). Return null when the given number of idle
* iterations is reached.
*/
@Override
public Neighbour<Exam, ExamPlacement> selectNeighbour(Solution<Exam, ExamPlacement> solution) {
Context context = getContext(solution.getAssignment());
context.activateIfNeeded();
while (true) {
if (context.incIter(solution)) break;
NeighbourSelection<Exam, ExamPlacement> ns = iNeighbours.get(ToolBox.random(iNeighbours.size()));
Neighbour<Exam, ExamPlacement> n = ns.selectNeighbour(solution);
if (n != null) {
if (n instanceof LazyNeighbour) {
((LazyNeighbour<Exam,ExamPlacement>)n).setAcceptanceCriterion(this);
return n;
} else if (n.value(solution.getAssignment()) <= 0.0) return n;
}
}
context.reset();
return null;
}
示例6: init
import org.cpsolver.ifs.heuristics.NeighbourSelection; //导入依赖的package包/类
@Override
public void init(Solver<V, T> solver) {
super.init(solver);
iProgress = Progress.getInstance(solver.currentSolution().getModel());
iSolver = solver;
solver.currentSolution().addSolutionListener(this);
// solver.setUpdateProgress(false);
for (NeighbourSelection<V, T> neighbour: iNeighbours)
neighbour.init(solver);
iTotalBonus = 0;
for (NeighbourSelector<V,T> s: iNeighbours) {
s.init(solver);
iTotalBonus += s.getBonus();
}
}
示例7: nextNeighbourSelection
import org.cpsolver.ifs.heuristics.NeighbourSelection; //导入依赖的package包/类
/**
* Generate and return next neighbour selection
* @return next neighbour selection to use
*/
protected NeighbourSelection<V,T> nextNeighbourSelection() {
NeighbourSelector<V,T> ns = null;
if (iRandomSelection) {
ns = ToolBox.random(iNeighbours);
} else {
double points = (ToolBox.random() * totalPoints());
for (Iterator<NeighbourSelector<V,T>> i = iNeighbours.iterator(); i.hasNext(); ) {
ns = i.next();
points -= (iUpdatePoints ? ns.getPoints() : ns.getBonus());
if (points <= 0) break;
}
}
return ns;
}
示例8: init
import org.cpsolver.ifs.heuristics.NeighbourSelection; //导入依赖的package包/类
/** Initialization */
@Override
public void init(Solver<Exam, ExamPlacement> solver) {
super.init(solver);
solver.currentSolution().addSolutionListener(this);
for (NeighbourSelection<Exam, ExamPlacement> neighbour: iNeighbours)
neighbour.init(solver);
solver.setUpdateProgress(false);
iProgress = Progress.getInstance(solver.currentSolution().getModel());
getContext(solver.currentSolution().getAssignment()).reset();
}
示例9: genMove
import org.cpsolver.ifs.heuristics.NeighbourSelection; //导入依赖的package包/类
/**
* Generate neighbour -- select neighbourhood randomly, select neighbour
* @param solution current solution
* @return a neigbour that was selected
*/
public Neighbour<Exam, ExamPlacement> genMove(Solution<Exam, ExamPlacement> solution) {
while (true) {
incIter(solution);
NeighbourSelection<Exam, ExamPlacement> ns = iNeighbours.get(ToolBox.random(iNeighbours.size()));
Neighbour<Exam, ExamPlacement> n = ns.selectNeighbour(solution);
if (n != null)
return n;
}
}
示例10: ExamSimulatedAnnealing
import org.cpsolver.ifs.heuristics.NeighbourSelection; //导入依赖的package包/类
/**
* Constructor. Following problem properties are considered:
* <ul>
* <li>SimulatedAnnealing.InitialTemperature ... initial temperature
* (default 1.5)
* <li>SimulatedAnnealing.TemperatureLength ... temperature length (number
* of iterations between temperature decrements, default 25000)
* <li>SimulatedAnnealing.CoolingRate ... temperature cooling rate (default
* 0.95)
* <li>SimulatedAnnealing.ReheatLengthCoef ... temperature re-heat length
* coefficient (multiple of temperature length, default 5)
* <li>SimulatedAnnealing.ReheatRate ... temperature re-heating rate
* (default (1/coolingRate)^(reheatLengthCoef*1.7))
* <li>SimulatedAnnealing.RestoreBestLengthCoef ... restore best length
* coefficient (multiple of re-heat length, default reheatLengthCoef^2)
* <li>SimulatedAnnealing.StochasticHC ... true for stochastic search
* acceptance criterion, false for simulated annealing acceptance (default
* false)
* <li>SimulatedAnnealing.RelativeAcceptance ... true for relative
* acceptance (different between the new and the current solutions, if the
* neighbour is accepted), false for absolute acceptance (difference between
* the new and the best solutions, if the neighbour is accepted)
* </ul>
*
* @param properties
* problem properties
*/
@SuppressWarnings("unchecked")
public ExamSimulatedAnnealing(DataProperties properties) {
iInitialTemperature = properties
.getPropertyDouble("SimulatedAnnealing.InitialTemperature", iInitialTemperature);
iReheatRate = properties.getPropertyDouble("SimulatedAnnealing.ReheatRate", iReheatRate);
iCoolingRate = properties.getPropertyDouble("SimulatedAnnealing.CoolingRate", iCoolingRate);
iRelativeAcceptance = properties.getPropertyBoolean("SimulatedAnnealing.RelativeAcceptance",
iRelativeAcceptance);
iStochasticHC = properties.getPropertyBoolean("SimulatedAnnealing.StochasticHC", iStochasticHC);
iTemperatureLength = properties.getPropertyLong("SimulatedAnnealing.TemperatureLength", iTemperatureLength);
iReheatLengthCoef = properties.getPropertyDouble("SimulatedAnnealing.ReheatLengthCoef", iReheatLengthCoef);
iRestoreBestLengthCoef = properties.getPropertyDouble("SimulatedAnnealing.RestoreBestLengthCoef",
iRestoreBestLengthCoef);
if (iReheatRate < 0)
iReheatRate = Math.pow(1 / iCoolingRate, iReheatLengthCoef * 1.7);
if (iRestoreBestLengthCoef < 0)
iRestoreBestLengthCoef = iReheatLengthCoef * iReheatLengthCoef;
String neighbours = properties.getProperty("SimulatedAnnealing.Neighbours",
ExamRandomMove.class.getName() + ";" +
ExamRoomMove.class.getName() + ";" +
ExamTimeMove.class.getName());
neighbours += ";" + properties.getProperty("SimulatedAnnealing.AdditionalNeighbours", "");
iNeighbours = new ArrayList<NeighbourSelection<Exam,ExamPlacement>>();
for (String neighbour: neighbours.split("\\;")) {
if (neighbour == null || neighbour.isEmpty()) continue;
try {
Class<NeighbourSelection<Exam, ExamPlacement>> clazz = (Class<NeighbourSelection<Exam, ExamPlacement>>)Class.forName(neighbour);
iNeighbours.add(clazz.getConstructor(DataProperties.class).newInstance(properties));
} catch (Exception e) {
sLog.error("Unable to use " + neighbour + ": " + e.getMessage());
}
}
}
示例11: init
import org.cpsolver.ifs.heuristics.NeighbourSelection; //导入依赖的package包/类
/**
* Initialization
*/
@Override
public void init(Solver<Exam, ExamPlacement> solver) {
super.init(solver);
iReheatLength = Math.round(iReheatLengthCoef * iTemperatureLength);
iRestoreBestLength = Math.round(iRestoreBestLengthCoef * iTemperatureLength);
solver.currentSolution().addSolutionListener(this);
for (NeighbourSelection<Exam, ExamPlacement> neighbour: iNeighbours)
neighbour.init(solver);
solver.setUpdateProgress(false);
iProgress = Progress.getInstance(solver.currentSolution().getModel());
}
示例12: genMove
import org.cpsolver.ifs.heuristics.NeighbourSelection; //导入依赖的package包/类
/**
* Generate neighbour -- select neighbourhood randomly, select neighbour
* @param solution current solutoon
* @return generated neighbour
*/
public Neighbour<Exam, ExamPlacement> genMove(Solution<Exam, ExamPlacement> solution) {
while (true) {
getContext(solution.getAssignment()).incIter(solution);
NeighbourSelection<Exam, ExamPlacement> ns = iNeighbours.get(ToolBox.random(iNeighbours.size()));
Neighbour<Exam, ExamPlacement> n = ns.selectNeighbour(solution);
if (n != null)
return n;
}
}
示例13: init
import org.cpsolver.ifs.heuristics.NeighbourSelection; //导入依赖的package包/类
/**
* Initialization
*/
@Override
public void init(Solver<Exam, ExamPlacement> solver) {
super.init(solver);
solver.currentSolution().addSolutionListener(this);
for (NeighbourSelection<Exam, ExamPlacement> neighbour: iNeighbours)
neighbour.init(solver);
solver.setUpdateProgress(false);
iProgress = Progress.getInstance(solver.currentSolution().getModel());
getContext(solver.currentSolution().getAssignment()).reset();
}
示例14: FixCompleteSolutionNeighbourSelection
import org.cpsolver.ifs.heuristics.NeighbourSelection; //导入依赖的package包/类
public FixCompleteSolutionNeighbourSelection(DataProperties config, NeighbourSelection<Lecture, Placement> parent) throws Exception {
iParent = parent;
iSuggestions = new NeighbourSelectionWithSuggestions(config);
}
示例15: setNeighbourSelection
import org.cpsolver.ifs.heuristics.NeighbourSelection; //导入依赖的package包/类
/** Sets neighbour selection criterion
* @param neighbourSelection neighbour selection criterion
**/
public void setNeighbourSelection(NeighbourSelection<V, T> neighbourSelection) {
iNeighbourSelection = neighbourSelection;
}