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


Java Assignment.assign方法代码示例

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


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

示例1: assign

import org.cpsolver.ifs.assignment.Assignment; //导入方法依赖的package包/类
@Override
public void assign(Assignment<Exam, ExamPlacement> assignment, long iteration) {
    if (sCheck) {
        double beforeVal = getVariable().getModel().getTotalValue(assignment);
        double[] beforeValM = ((ExamModel) getVariable().getModel()).getTotalMultiValue(assignment);
        String n = toString();
        assignment.assign(iteration, getValue());
        double afterVal = getVariable().getModel().getTotalValue(assignment);
        double[] afterValM = ((ExamModel) getVariable().getModel()).getTotalMultiValue(assignment);
        /*
         * int before = getVariable().getModel().nrUnassignedVariables();
         * int after = getVariable().getModel().nrUnassignedVariables(); if
         * (after>before) {
         * sLog.error("-- assignment mischmatch (delta:"+(after
         * -before)+")"); sLog.error("  -- neighbour: "+n); }
         */
        if (Math.abs(afterVal - beforeVal - iDx) >= 0.0000001) {
            sLog.error("-- value mischmatch (delta:" + (afterVal - beforeVal) + ", value:" + iDx + ")");
            sLog.error("  -- neighbour: " + n);
            sLog.error("  -- solution:  " + toString(afterValM, beforeValM));
        }
    } else {
        assignment.assign(iteration, getValue());
    }
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:26,代码来源:ExamSimpleNeighbour.java

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: split

import org.cpsolver.ifs.assignment.Assignment; //导入方法依赖的package包/类
/**
 * Split an exam
 * @param assignment current assignment
 * @param parent an exam to be split
 * @param iteration solver iteration
 * @param placement placement of the new exam
 * @return new exam assigned to the given placement with students moved into it; null if the given exam cannot be split
 */
public Exam split(Assignment<Exam, ExamPlacement> assignment, Exam parent, long iteration, ExamPlacement placement) {
    if (!canSplit(parent)) return null;

    // Create the child exam
    Exam child = new Exam(--iLastSplitId, parent.getName(), parent.getLength(), parent.hasAltSeating(), parent.getMaxRooms(), parent.getMinSize(), parent.getPeriodPlacements(), parent.getRoomPlacements());
    child.setSizeOverride(parent.getSizeOverride());
    child.setPrintOffset(parent.getPrintOffset());
    child.setAveragePeriod(parent.getAveragePeriod());
    child.getOwners().addAll(parent.getOwners());
    
    // Update the parent and children structures
    iParent.put(child, parent);
    List<Exam> children = iChildren.get(parent);
    if (children == null) {
        children = new ArrayList<Exam>();
        iChildren.put(parent, children);
    }
    children.add(child);
    iValue += 1.0;
    
    // Add into model
    parent.getModel().addVariable(child);
    for (ExamRoomPlacement room : child.getRoomPlacements()) 
        room.getRoom().addVariable(child);
    if (placement != null) assignment.assign(iteration, new ExamPlacement(child, placement.getPeriodPlacement(), placement.getRoomPlacements()));
    
    
    // Shuffle students between parent exam and its children
    shuffle(assignment, parent, iteration);

    // Return the new exam
    return child;
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:42,代码来源:ExamSplitter.java

示例10: 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

示例11: 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

示例12: assign

import org.cpsolver.ifs.assignment.Assignment; //导入方法依赖的package包/类
@Override
public void assign(Assignment<CurVariable, CurValue> assignment, long iteration) {
	assignment.assign(iteration, iNewValue);
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:5,代码来源:CurSimpleAssignment.java

示例13: fixCompleteSolution

import org.cpsolver.ifs.assignment.Assignment; //导入方法依赖的package包/类
/**
 * Try to improve existing solution by backtracking search of very limited
 * depth. See {@link NeighbourSelectionWithSuggestions} for more details.
 * @param solution current solution
 * @param startTime start time
 */
protected void fixCompleteSolution(Solution<Lecture, Placement> solution, double startTime) {
    Progress progress = Progress.getInstance(solution.getModel());

    TimetableModel model = (TimetableModel) solution.getModel();
    Assignment<Lecture, Placement> assignment = solution.getAssignment();
    solution.saveBest();
    progress.save();
    double solutionValue = 0.0, newSolutionValue = model.getTotalValue(assignment);
    do {
        solutionValue = newSolutionValue;
        progress.setPhase("Fixing solution", model.variables().size());
        for (Lecture variable : model.variables()) {
            Placement bestValue = null;
            double bestVal = 0.0;
            Placement currentValue = assignment.getValue(variable);
            if (currentValue == null)
                continue;
            double currentVal = currentValue.toDouble(assignment);
            for (Placement value : variable.values()) {
                if (value.equals(currentValue))
                    continue;
                if (model.conflictValues(assignment, value).isEmpty()) {
                    double val = value.toDouble(assignment);
                    if (bestValue == null || val < bestVal) {
                        bestValue = value;
                        bestVal = val;
                    }
                }
            }
            if (bestValue != null && bestVal < currentVal)
                assignment.assign(0, bestValue);
            solution.update(JProf.currentTimeSec() - startTime);
            progress.incProgress();
            if (iStop)
                break;
        }
        newSolutionValue = model.getTotalValue(assignment);
        if (newSolutionValue < solutionValue) {
            progress.debug("New solution value is  " + newSolutionValue);
        }
    } while (!iStop && newSolutionValue < solutionValue && getTerminationCondition().canContinue(solution));
    progress.restore();

    if (!solution.getModel().unassignedVariables(assignment).isEmpty())
        return;
    progress.save();
    try {
        progress.setPhase("Fixing solution [2]", model.variables().size());
        NeighbourSelectionWithSuggestions ns = new NeighbourSelectionWithSuggestions(this);
        for (Lecture lecture : model.variables()) {
            Neighbour<Lecture, Placement> n = ns.selectNeighbourWithSuggestions(solution, lecture, 2);
            if (n != null && n.value(assignment) <= 0.0)
                n.assign(assignment, 0);
            solution.update(JProf.currentTimeSec() - startTime);
            progress.incProgress();
            if (iStop)
                break;
        }
    } catch (Exception e) {
        sLogger.debug(e.getMessage(), e);
    } finally {
        progress.restore();
    }
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:71,代码来源:TimetableSolver.java


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