当前位置: 首页>>代码示例>>Java>>正文


Java Assignment.unassign方法代码示例

本文整理汇总了Java中org.cpsolver.ifs.assignment.Assignment.unassign方法的典型用法代码示例。如果您正苦于以下问题:Java Assignment.unassign方法的具体用法?Java Assignment.unassign怎么用?Java Assignment.unassign使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.cpsolver.ifs.assignment.Assignment的用法示例。


在下文中一共展示了Assignment.unassign方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: beforeAssigned

import org.cpsolver.ifs.assignment.Assignment; //导入方法依赖的package包/类
/**
 * Before a value is unassigned: until the value is inconsistent with the
 * current solution, an assignment from its explanation is picked and
 * unassigned.
 */
@Override
public void beforeAssigned(Assignment<V, T> assignment, long iteration, T value) {
    if (value == null)
        return;
    sLogger.debug("Before assign " + value.variable().getName() + " = " + value.getName());
    iIteration = iteration;
    NoGood context = getContext(assignment);
    while (!context.isGood(value) && !context.noGood(value).isEmpty()) {
        if (iDbt)
            sLogger.warn("Going to assign a no-good value " + value + " (noGood:" + context.noGood(value) + ").");
        T noGoodValue = context.noGood(value).iterator().next();
        assignment.unassign(iteration, noGoodValue.variable());
    }
    if (!context.isGood(value)) {
        sLogger.warn("Going to assign a bad value " + value + " with empty no-good.");
    }
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:23,代码来源:MacRevised.java

示例2: beforeAssigned

import org.cpsolver.ifs.assignment.Assignment; //导入方法依赖的package包/类
/**
 * Before a value is unassigned: until the value is inconsistent with the
 * current solution, an assignment from its explanation is picked and
 * unassigned.
 */
@Override
public void beforeAssigned(Assignment<V, T> assignment, long iteration, T value) {
    iIteration = iteration;
    if (value == null)
        return;
    if (!isGood(assignment, value)) {
        while (!isGood(assignment, value) && !noGood(assignment, value).isEmpty()) {
            T noGoodValue = noGood(assignment, value).iterator().next();
            assignment.unassign(iteration, noGoodValue.variable());
        }
    }
    if (!isGood(assignment, value)) {
        sLogger.warn("Going to assign a bad value " + value + " with empty no-good.");
    }
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:21,代码来源:MacPropagation.java

示例3: assigned

import org.cpsolver.ifs.assignment.Assignment; //导入方法依赖的package包/类
/**
 * An exam was assigned, update room assignment table
 */
@Override
public void assigned(Assignment<Exam, ExamPlacement> assignment, long iteration, ExamPlacement p) {
    if (p.contains(this)) {
        if (!getContext(assignment).getPlacements(p.getPeriod().getIndex()).isEmpty()) {
            HashSet<ExamPlacement> confs = new HashSet<ExamPlacement>();
            computeConflicts(assignment, p, confs);
            for (ExamPlacement conf: confs)
                assignment.unassign(iteration, conf.variable());
            if (iConstraintListeners != null) {
                for (ConstraintListener<Exam, ExamPlacement> listener : iConstraintListeners)
                    listener.constraintAfterAssigned(assignment, iteration, this, p, confs);
            }
        }
        getContext(assignment).assigned(assignment, p);
    }
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:20,代码来源:ExamRoom.java

示例4: assign

import org.cpsolver.ifs.assignment.Assignment; //导入方法依赖的package包/类
/**
 * Only assign given number of assignments (from the first priority down).
 * Mark the cycle as improving if there was enough assignments to do.
 */
@Override
public void assign(Assignment<Request, Enrollment> assignment, long iteration) {
    if (iCycle >= iMaxCycles) {
        iNeighbour.assign(assignment, iteration);
        return;
    }
    for (Request r: iNeighbour.getStudent().getRequests())
        assignment.unassign(iteration, r);
    int n = iCycle;
    for (int i = 0; i < iNeighbour.getAssignment().length; i++) {
        if (iNeighbour.getAssignment()[i] != null) {
            assignment.assign(iteration, iNeighbour.getAssignment()[i]);
            n --;
        }
        if (n == 0) {
            iImproved = true; break;
        }
    }
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:24,代码来源:PriorityConstructionSelection.java

示例5: resolve

import org.cpsolver.ifs.assignment.Assignment; //导入方法依赖的package包/类
@Override
public Double resolve(Solution<Lecture, Placement> solution, double total, long startTime, Map<Lecture, Placement> assignments, List<Placement> conflicts, int index) {
    Assignment<Lecture, Placement> assignment = solution.getAssignment();
    
    if (index == conflicts.size()) return solution.getModel().getTotalValue(assignment) - total;
    Placement conflict = conflicts.get(index);
    Lecture variable = conflict.variable();
    
    if (conflict.getNrRooms() != 1) return null;

    List<RoomLocation> values = variable.roomLocations();
    if (values.isEmpty()) return null;
    
    int valIdx = ToolBox.random(values.size());
    int attempts = 0;
    for (int i = 0; i < values.size(); i++) {
        RoomLocation room = values.get((i + valIdx) % values.size());
        if (room.getPreference() > 50) continue;
        if (room.equals(conflict.getRoomLocation())) continue;
        
        Placement value = new Placement(variable, conflict.getTimeLocation(), room);
        if (!value.isValid() || solution.getModel().inConflict(assignment, value)) continue;
        
        assignment.assign(solution.getIteration(), value);
        Double v = resolve(solution, total, startTime, assignments, conflicts, 1 + index);
        assignment.unassign(solution.getIteration(), variable);
        attempts ++;
        
        if (v != null && (!iHC || v <= 0)) {
            assignments.put(variable, value);
            return v;
        }
        if (attempts >= iMaxAttempts || isTimeLimitReached(startTime)) break;
    }
        
    return null;
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:38,代码来源:RoomSwap.java

示例6: assign

import org.cpsolver.ifs.assignment.Assignment; //导入方法依赖的package包/类
/** Perform assignment */
@Override
public void assign(Assignment<V, T> assignment, long iteration) {
    if (iVariable == null)
        return;
    if (iValue != null)
        assignment.assign(iteration, iValue);
    else
        assignment.unassign(iteration, iVariable);
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:11,代码来源:SimpleNeighbour.java

示例7: doAssign

import org.cpsolver.ifs.assignment.Assignment; //导入方法依赖的package包/类
/** Perform swap */
@Override
protected void doAssign(Assignment<V, T> assignment, long iteration) {
    iOldV1 = assignment.getValue(iV1.variable());
    iOldV2 = assignment.getValue(iV2.variable());
    if (iOldV1 != null) assignment.unassign(iteration, iV1.variable());
    if (iOldV2 != null) assignment.unassign(iteration, iV2.variable());
    assignment.assign(iteration, iV1);
    assignment.assign(iteration, iV2);
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:11,代码来源:LazySwap.java

示例8: undoAssign

import org.cpsolver.ifs.assignment.Assignment; //导入方法依赖的package包/类
/** Undo the swap */
@Override
protected void undoAssign(Assignment<V, T> assignment, long iteration) {
    assignment.unassign(iteration, iV1.variable());
    assignment.unassign(iteration, iV2.variable());
    if (iOldV1 != null) assignment.assign(iteration, iOldV1);
    if (iOldV2 != null) assignment.assign(iteration, iOldV2);
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:9,代码来源:LazySwap.java

示例9: resolve

import org.cpsolver.ifs.assignment.Assignment; //导入方法依赖的package包/类
/**
 * Try to resolve given conflicts. For each conflicting variable it tries to find a 
 * value with no conflict that is compatible with some other assignment
 * of the other conflicting variables. 
 * @param solution current solution
 * @param total original value of the current solution
 * @param startTime starting time
 * @param assignments re-assignments to be made
 * @param conflicts list of conflicts to resolve
 * @param index index in the list of conflicts
 * @return value of the modified solution, null if cannot be resolved
 */
protected Double resolve(Solution<V, T> solution, double total, long startTime, Map<V, T> assignments, List<T> conflicts, int index) {
    Assignment<V, T> assignment = solution.getAssignment();

    if (index == conflicts.size()) return solution.getModel().getTotalValue(assignment) - total;
    T conflict = conflicts.get(index);
    V variable = conflict.variable();
    
    List<T> values = variable.values(solution.getAssignment());
    if (values.isEmpty()) return null;
    
    int valIdx = ToolBox.random(values.size());
    int attempts = 0;
    for (int i = 0; i < values.size(); i++) {
        T value = values.get((i + valIdx) % values.size());
        if (value.equals(conflict) || solution.getModel().inConflict(assignment, value)) continue;
        
        assignment.assign(solution.getIteration(), value);
        Double v = resolve(solution, total, startTime, assignments, conflicts, 1 + index);
        assignment.unassign(solution.getIteration(), variable);
        attempts ++;
        
        if (v != null && (!iHC || v <= 0)) {
            assignments.put(variable, value);
            return v;
        }
        if (attempts >= iMaxAttempts || isTimeLimitReached(startTime)) break;
    }
        
    return null;
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:43,代码来源:RandomSwapMove.java

示例10: assign

import org.cpsolver.ifs.assignment.Assignment; //导入方法依赖的package包/类
@Override
public void assign(Assignment<Exam, ExamPlacement> assignment, long iteration) {
    if (iX2 == null) {
        assignment.assign(iteration, iX1);
    } else {
        assignment.unassign(iteration, iX1.variable());
        assignment.unassign(iteration, iX2.variable());
        assignment.assign(iteration, iX1);
        assignment.assign(iteration, iX2);
    }
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:12,代码来源:ExamRoomSwapNeighbour.java

示例11: merge

import org.cpsolver.ifs.assignment.Assignment; //导入方法依赖的package包/类
/**
 * Merge an exam
 * @param assignment current assignment
 * @param child an exam to be merged
 * @param iteration solver iteration
 * @return parent exam of the exam that has been deleted; null if the given exam cannot be merged
 */
public Exam merge(Assignment<Exam, ExamPlacement> assignment, Exam child, long iteration) {
    if (!canMerge(child)) return null;
    
    // Update the parent and children structures
    Exam parent = iParent.get(child);
    iParent.remove(child);
    List<Exam> children = iChildren.get(parent);
    children.remove(child);
    iValue -= 1.0;
    
    // Unassign parent and the given exam
    ExamPlacement parentPlacement = assignment.getValue(parent);
    if (parentPlacement != null) assignment.unassign(iteration, parent);
    if (assignment.getValue(child) != null) assignment.unassign(iteration, child);

    // Move students back from the given exam
    for (ExamStudent student: new ArrayList<ExamStudent>(child.getStudents())) {
        student.removeVariable(child);
        student.addVariable(parent);
    }
    
    // Remove the given exam from the model
    for (ExamRoomPlacement room : child.getRoomPlacements()) 
        room.getRoom().removeVariable(child);
    parent.getModel().removeVariable(child);
    
    // Assign parent exam back
    if (parentPlacement != null) assignment.assign(iteration, parentPlacement);
    
    
    // Shuffle students between parent exam and its remaining children
    shuffle(assignment, parent, iteration);
    
    // Return parent exam
    return parent;
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:44,代码来源:ExamSplitter.java

示例12: assign

import org.cpsolver.ifs.assignment.Assignment; //导入方法依赖的package包/类
/** Assign the schedule */
@Override
public void assign(Assignment<Request, Enrollment> assignment, long iteration) {
    for (Request r: iStudent.getRequests())
        assignment.unassign(iteration, r);
    for (int i = 0; i < iAssignment.length; i++)
        if (iAssignment[i] != null)
            assignment.assign(iteration, iAssignment[i]);
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:10,代码来源:BranchBoundSelection.java

示例13: assign

import org.cpsolver.ifs.assignment.Assignment; //导入方法依赖的package包/类
/** All requests of the given student are unassigned */
@Override
public void assign(Assignment<Request, Enrollment> assignment, long iteration) {
    for (Request request : iRequests)
        assignment.unassign(iteration, request);
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:7,代码来源:RandomUnassignmentSelection.java


注:本文中的org.cpsolver.ifs.assignment.Assignment.unassign方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。