本文整理汇总了Java中org.cpsolver.ifs.model.Model类的典型用法代码示例。如果您正苦于以下问题:Java Model类的具体用法?Java Model怎么用?Java Model使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Model类属于org.cpsolver.ifs.model包,在下文中一共展示了Model类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setModel
import org.cpsolver.ifs.model.Model; //导入依赖的package包/类
@Override
public void setModel(Model<Lecture, Placement> model) {
super.setModel(model);
if (model != null) {
DataProperties config = ((TimetableModel)model).getProperties();
iDayOfWeekOffset = config.getPropertyInt("DatePattern.DayOfWeekOffset", 0);
iPrecedenceConsiderDatePatterns = config.getPropertyBoolean("Precedence.ConsiderDatePatterns", true);
iForwardCheckMaxDepth = config.getPropertyInt("ForwardCheck.MaxDepth", iForwardCheckMaxDepth);
iForwardCheckMaxDomainSize = config.getPropertyInt("ForwardCheck.MaxDomainSize", iForwardCheckMaxDomainSize);
iMaxNHoursADayConsiderDatePatterns = config.getPropertyBoolean("MaxNHoursADay.ConsiderDatePatterns", iMaxNHoursADayConsiderDatePatterns);
iNrWorkDays = (config.getPropertyInt("General.LastWorkDay", 4) - config.getPropertyInt("General.FirstWorkDay", 0) + 1);
if (iNrWorkDays <= 0) iNrWorkDays += 7;
if (iNrWorkDays > 7) iNrWorkDays -= 7;
iFirstWorkDay = config.getPropertyInt("General.FirstWorkDay", 0);
}
}
示例2: getPerturbationPenalty
import org.cpsolver.ifs.model.Model; //导入依赖的package包/类
@Override
public double getPerturbationPenalty(Assignment<V, T> assignment, Model<V, T> model, T selectedValue, Collection<T> conflicts) {
double penalty = 0;
Set<T> violations = (getViolatedInitials() == null ? null : getViolatedInitials().getViolatedInitials(selectedValue));
if (violations != null)
for (T aValue : violations) {
if (assignment.getValue(aValue.variable()) == null)
penalty += getPenaltyA(assignment, selectedValue, aValue);
}
if (conflicts != null) {
for (T conflictValue : conflicts) {
T initialValue = conflictValue.variable().getInitialAssignment();
if (initialValue != null) {
if (initialValue.equals(conflictValue))
penalty += getPenaltyB(assignment, selectedValue, conflictValue, initialValue);
else {
if (violations == null || !violations.contains(initialValue))
penalty += getPenaltyC(assignment, selectedValue, conflictValue, initialValue);
}
}
}
}
if (selectedValue.variable().getInitialAssignment() != null && !selectedValue.equals(selectedValue.variable().getInitialAssignment()))
penalty += getPenaltyD(assignment, selectedValue, selectedValue.variable().getInitialAssignment());
return penalty;
}
示例3: accept
import org.cpsolver.ifs.model.Model; //导入依赖的package包/类
/**
* True if the given neighbour is to be be accepted
*
* @param assignment
* current assignment
* @param neighbour
* proposed move
* @return true if generated random number is below the generated probability
*/
@Override
protected boolean accept(Assignment<V, T> assignment, Model<V, T> model, Neighbour<V, T> neighbour, double value, boolean lazy) {
iMoves ++;
iAbsValue += value * value;
double v = (iRelativeAcceptance ? value : (lazy ? model.getTotalValue(assignment) : value + model.getTotalValue(assignment)) - iBestValue);
if (iTrainingIterations < iTrainingValues) {
if (v <= 0.0) {
iAcceptIter[value < 0.0 ? 0 : value > 0.0 ? 2 : 1]++;
return true;
} else {
iTrainingIterations ++; iTrainingTotal += v;
}
return false;
}
double prob = prob(v);
if (v > 0) {
iTrainingIterations ++; iTrainingTotal += v;
}
if (prob >= 1.0 || ToolBox.random() < prob) {
iAcceptIter[value < 0.0 ? 0 : value > 0.0 ? 2 : 1]++;
return true;
}
return false;
}
示例4: selectNeighbour
import org.cpsolver.ifs.model.Model; //导入依赖的package包/类
@Override
public Neighbour<V, T> selectNeighbour(Solution<V, T> solution) {
Model<V, T> model = solution.getModel();
Assignment<V, T> assignment = solution.getAssignment();
int varIdx = ToolBox.random(model.variables().size());
for (int i = 0; i < model.variables().size(); i++) {
V variable = model.variables().get((i + varIdx) % model.variables().size());
List<T> values = variable.values(solution.getAssignment());
if (values.isEmpty()) continue;
int valIdx = ToolBox.random(values.size());
for (int j = 0; j < values.size(); j++) {
T value = values.get((j + valIdx) % values.size());
if (!model.inConflict(assignment, value)) {
SimpleNeighbour<V, T> n = new SimpleNeighbour<V, T>(variable, value);
if (!iHC || n.value(assignment) <= 0) return n;
}
}
}
return null;
}
示例5: selectNeighbour
import org.cpsolver.ifs.model.Model; //导入依赖的package包/类
@Override
public Neighbour<V, T> selectNeighbour(Solution<V, T> solution) {
if (iBestValue != null && iBestIndex != solution.getAssignment().getIndex()) {
ConstructionContext context = getContext(solution.getAssignment());
if (solution.getAssignment().nrAssignedVariables() == iBestAssigned) {
context.reset();
} else if (solution.getAssignment().nrAssignedVariables() < iBestAssigned && context.inc() >= iMaxIdle) {
Model<V, T> model = solution.getModel();
Assignment<V, T> assignment = solution.getAssignment();
int idx = ToolBox.random(model.countVariables());
for (int i = 0; i < model.countVariables(); i++) {
V variable = model.variables().get((i + idx) % model.countVariables());
T value = assignment.getValue(variable);
T best = variable.getBestAssignment();
if (value == null && best != null)
return new SimpleNeighbour<V, T>(variable, best, model.conflictValues(solution.getAssignment(), best));
}
}
}
return iParent.selectNeighbour(solution);
}
示例6: setModel
import org.cpsolver.ifs.model.Model; //导入依赖的package包/类
@Override
public void setModel(Model<Lecture, Placement> model) {
super.setModel(model);
if (model != null && model instanceof TimetableModel) {
DataProperties config = ((TimetableModel)model).getProperties();
iJenrlMaxConflicts = config.getPropertyDouble("General.JenrlMaxConflicts", 1.0);
iJenrlMaxConflictsWeaken = config.getPropertyDouble("General.JenrlMaxConflictsWeaken", 0.001);
}
}
示例7: unassignedVariables
import org.cpsolver.ifs.model.Model; //导入依赖的package包/类
@Override
public Collection<V> unassignedVariables(Model<V, T> model) {
List<V> unassigned = new ArrayList<V>();
for (V variable: model.variables())
if (getValue(variable) == null)
unassigned.add(variable);
return unassigned;
}
示例8: Solution
import org.cpsolver.ifs.model.Model; //导入依赖的package包/类
/** Constructor
* @param model problem model
* @param assignment current assignment
* @param iteration current iteration
* @param time current solver time
**/
public Solution(Model<V, T> model, Assignment<V, T> assignment, long iteration, double time) {
iModel = model;
iAssignment = assignment;
iIteration = iteration;
iTime = time;
}
示例9: setInitalSolution
import org.cpsolver.ifs.model.Model; //导入依赖的package包/类
/** Sets initial solution */
@Override
public void setInitalSolution(Model<V, T> model) {
int nrSolvers = Math.min(Math.abs(getProperties().getPropertyInt("Parallel.NrSolvers", 4)), CanHoldContext.sMaxSize - 1);
boolean updateMasterSolution = getProperties().getPropertyBoolean("Parallel.UpdateMasterSolution", true);
setInitalSolution(new Solution<V, T>(model, nrSolvers > 1 ? new DefaultParallelAssignment<V, T>(updateMasterSolution ? 1 : 0) : new DefaultSingleAssignment<V, T>(), 0, 0));
}
示例10: createParallelSolution
import org.cpsolver.ifs.model.Model; //导入依赖的package包/类
/**
* Create a solution that is to be used by a solver thread of the given index
* @param index solver thread index
* @return new solution to work with
*/
protected Solution<V, T> createParallelSolution(int index) {
Model<V, T> model = iCurrentSolution.getModel();
Assignment<V, T> assignment = new DefaultParallelAssignment<V, T>(index, model, iCurrentSolution.getAssignment());
model.createAssignmentContexts(assignment, true);
Solution<V, T> solution = new Solution<V, T>(model, assignment);
for (SolutionListener<V, T> listener: iCurrentSolution.getSolutionListeners())
solution.addSolutionListener(listener);
return solution;
}
示例11: accept
import org.cpsolver.ifs.model.Model; //导入依赖的package包/类
/** Accept the given neighbour if it does not worsen the current solution or when the new solution is below the bound */
@Override
protected boolean accept(Assignment<V, T> assignment, Model<V, T> model, Neighbour<V, T> neighbour, double value, boolean lazy) {
iMoves ++;
if (value <= 0.0 || (lazy ? model.getTotalValue(assignment) : value + model.getTotalValue(assignment)) < iBound) {
iAcceptedMoves ++;
return true;
}
return false;
}
示例12: bestSaved
import org.cpsolver.ifs.model.Model; //导入依赖的package包/类
protected void bestSaved(Model<Exam, ExamPlacement> model) {
if (Math.abs(iBestValue - model.getBestValue()) >= 1.0) {
iLastImprovingIter = iIter;
iNrIdle = 0;
iBestValue = model.getBestValue();
}
}
示例13: getModel
import org.cpsolver.ifs.model.Model; //导入依赖的package包/类
@Override
public Model<CurVariable, CurValue> getModel() {
return null;
}
示例14: setInitalSolution
import org.cpsolver.ifs.model.Model; //导入依赖的package包/类
@Override
public void setInitalSolution(Model<Request, Enrollment> model) {
setInitalSolution(new Solution(model, new DefaultSingleAssignment<Request, Enrollment>()));
}
示例15: setModel
import org.cpsolver.ifs.model.Model; //导入依赖的package包/类
@Override
public void setModel(Model<Lecture, Placement> model) {
super.setModel(model);
iNoonSlot = ((TimetableModel)model).getProperties().getPropertyInt("General.HalfDaySlot", iNoonSlot);
}