001    package ifs.example.jobshop;
002    
003    import ifs.model.*;
004    
005    /**
006     * Location of an operation.
007     * <br><br>
008     * Each location has its start time.
009     *
010     * @author <a href="mailto:muller@ktiml.mff.cuni.cz">Tomáš Müller</a>
011     * @version 1.0
012     */
013    public class Location extends Value {
014        private int iStartTime = -1;
015        
016        /**
017         * Constructor
018         * @param op parent operation
019         * @param startTime start time
020         */
021        public Location(Operation op, int startTime) {
022            super(op);
023            iStartTime = startTime;
024        }
025        
026        /**
027         * Get start time of the location
028         */
029        public int getStartTime() { return iStartTime; }
030        
031        /**
032         * Get finishing time of the location (start time + operation processing time)
033         */
034        public int getFinishingTime() { return iStartTime+((Operation)variable()).getProcessingTime()-1; }
035        
036        /**
037         * Start time of the location
038         */
039        public int toInt() { return iStartTime; }
040        
041        /**
042         * String representation (operation name = start time)
043         */
044        public String toString() { return variable().getName()+"="+iStartTime; }
045        
046        /**
047         * Name -- start time
048         */
049        public String getName() { return String.valueOf(iStartTime); }
050        
051        /**
052         * Returns true if overlap with the given location
053         */
054        public boolean overlap(Location anotherLocation) {
055            if (getStartTime()+((Operation)variable()).getProcessingTime()<=anotherLocation.getStartTime()) return false;
056            if (anotherLocation.getStartTime()+((Operation)anotherLocation.variable()).getProcessingTime()<=getStartTime()) return false;
057            return true;
058        }
059        
060        /**
061         * Returnts true if before the given location
062         */
063        public boolean before(Location anotherLocation) {
064            if (getStartTime()+((Operation)variable()).getProcessingTime()<=anotherLocation.getStartTime()) return true;
065            return false;
066        }
067    
068        /**
069         * Returnts true if after the given location
070         */
071        public boolean after(Location anotherLocation) {
072            return anotherLocation.before(this);
073        }
074    }