001 package ifs.example.jobshop;
002
003 import ifs.model.*;
004 import java.util.*;
005
006 /**
007 * Machine constraint.
008 * <br><br>
009 * Each machine contians a given set of operations (variables).
010 * A machine constraint is satisfied, if all operations on it do not overlap in time.
011 *
012 * @author <a href="mailto:muller@ktiml.mff.cuni.cz">Tomáš Müller</a>
013 * @version 1.0
014 */
015 public class Machine extends Constraint {
016 private int iMachineNumber = -1;
017
018 /**
019 * Constructor
020 * @param machineNumber machine number
021 */
022 public Machine(int machineNumber) {
023 super();
024 iMachineNumber = machineNumber;
025 }
026
027 /** Get machine number */
028 public int getMachineNumber() { return iMachineNumber; }
029
030
031 /**
032 * Adds conflicting operations into the set of conflicts.
033 */
034 public void computeConflicts(Value value, java.util.Set conflicts) {
035 Location location = (Location)value;
036 Operation operation = (Operation)value.variable();
037 for (Enumeration e=assignedVariables().elements();e.hasMoreElements();) {
038 Operation o = (Operation)e.nextElement();
039 if (o.getOperationNumber()==operation.getOperationNumber() && o.getJobNumber()==operation.getJobNumber()) continue;
040 Location l = (Location)o.getAssignment();
041 if (l.overlap(location)) conflicts.add(l);
042 }
043 }
044
045 /**
046 * True if there is an operation from the machine which violates with the given assignment.
047 */
048 public boolean inConflict(Value value) {
049 Location location = (Location)value;
050 Operation operation = (Operation)value.variable();
051 for (Enumeration e=assignedVariables().elements();e.hasMoreElements();) {
052 Operation o = (Operation)e.nextElement();
053 if (o.getOperationNumber()==operation.getOperationNumber() && o.getJobNumber()==operation.getJobNumber()) continue;
054 Location l = (Location)o.getAssignment();
055 if (l.overlap(location)) return true;
056 }
057 return false;
058 }
059
060 /**
061 * True if the two assignments (placement of opeartions of the machine in time) violates each other.
062 */
063 public boolean isConsistent(Value value1, Value value2) {
064 return !((Location)value1).overlap((Location)value2);
065 }
066
067 /** string representation -- for debuging and printing purposes */
068 public String toString() { return getName(); }
069
070 /**
071 * Name of the machine (e.g. M10 where 10 is the machine number)
072 */
073 public String getName() { return "M"+iMachineNumber; }
074 }