001 package net.sf.cpsolver.ifs.example.jobshop; 002 003 import java.util.*; 004 005 import net.sf.cpsolver.ifs.model.*; 006 007 /** 008 * Machine constraint. 009 * <br><br> 010 * Each machine contians a given set of operations (variables). 011 * A machine constraint is satisfied, if all operations on it do not overlap in time. 012 * 013 * @version 014 * IFS 1.1 (Iterative Forward Search)<br> 015 * Copyright (C) 2006 Tomáš Müller<br> 016 * <a href="mailto:muller@unitime.org">muller@unitime.org</a><br> 017 * Lazenska 391, 76314 Zlin, Czech Republic<br> 018 * <br> 019 * This library is free software; you can redistribute it and/or 020 * modify it under the terms of the GNU Lesser General Public 021 * License as published by the Free Software Foundation; either 022 * version 2.1 of the License, or (at your option) any later version. 023 * <br><br> 024 * This library is distributed in the hope that it will be useful, 025 * but WITHOUT ANY WARRANTY; without even the implied warranty of 026 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 027 * Lesser General Public License for more details. 028 * <br><br> 029 * You should have received a copy of the GNU Lesser General Public 030 * License along with this library; if not, write to the Free Software 031 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 032 */ 033 public class Machine extends Constraint { 034 private int iMachineNumber = -1; 035 036 /** 037 * Constructor 038 * @param machineNumber machine number 039 */ 040 public Machine(int machineNumber) { 041 super(); 042 iMachineNumber = machineNumber; 043 } 044 045 /** Get machine number */ 046 public int getMachineNumber() { return iMachineNumber; } 047 048 049 /** 050 * Adds conflicting operations into the set of conflicts. 051 */ 052 public void computeConflicts(Value value, java.util.Set conflicts) { 053 Location location = (Location)value; 054 Operation operation = (Operation)value.variable(); 055 for (Enumeration e=assignedVariables().elements();e.hasMoreElements();) { 056 Operation o = (Operation)e.nextElement(); 057 if (o.getOperationNumber()==operation.getOperationNumber() && o.getJobNumber()==operation.getJobNumber()) continue; 058 Location l = (Location)o.getAssignment(); 059 if (l.overlap(location)) conflicts.add(l); 060 } 061 } 062 063 /** 064 * True if there is an operation from the machine which violates with the given assignment. 065 */ 066 public boolean inConflict(Value value) { 067 Location location = (Location)value; 068 Operation operation = (Operation)value.variable(); 069 for (Enumeration e=assignedVariables().elements();e.hasMoreElements();) { 070 Operation o = (Operation)e.nextElement(); 071 if (o.getOperationNumber()==operation.getOperationNumber() && o.getJobNumber()==operation.getJobNumber()) continue; 072 Location l = (Location)o.getAssignment(); 073 if (l.overlap(location)) return true; 074 } 075 return false; 076 } 077 078 /** 079 * True if the two assignments (placement of opeartions of the machine in time) violates each other. 080 */ 081 public boolean isConsistent(Value value1, Value value2) { 082 return !((Location)value1).overlap((Location)value2); 083 } 084 085 /** string representation -- for debuging and printing purposes */ 086 public String toString() { return getName(); } 087 088 /** 089 * Name of the machine (e.g. M10 where 10 is the machine number) 090 */ 091 public String getName() { return "M"+iMachineNumber; } 092 }