001package org.cpsolver.ifs.example.jobshop;
002
003import org.cpsolver.ifs.model.Value;
004
005/**
006 * Location of an operation. <br>
007 * <br>
008 * Each location has its start time.
009 * 
010 * @version IFS 1.3 (Iterative Forward Search)<br>
011 *          Copyright (C) 2006 - 2014 Tomáš Müller<br>
012 *          <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
013 *          <a href="http://muller.unitime.org">http://muller.unitime.org</a><br>
014 * <br>
015 *          This library is free software; you can redistribute it and/or modify
016 *          it under the terms of the GNU Lesser General Public License as
017 *          published by the Free Software Foundation; either version 3 of the
018 *          License, or (at your option) any later version. <br>
019 * <br>
020 *          This library is distributed in the hope that it will be useful, but
021 *          WITHOUT ANY WARRANTY; without even the implied warranty of
022 *          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
023 *          Lesser General Public License for more details. <br>
024 * <br>
025 *          You should have received a copy of the GNU Lesser General Public
026 *          License along with this library; if not see
027 *          <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>.
028 */
029public class Location extends Value<Operation, Location> {
030    private int iStartTime = -1;
031
032    /**
033     * Constructor
034     * 
035     * @param op
036     *            parent operation
037     * @param startTime
038     *            start time
039     */
040    public Location(Operation op, int startTime) {
041        super(op);
042        iStartTime = startTime;
043    }
044
045    /**
046     * Get start time of the location
047     * @return start time of the location
048     */
049    public int getStartTime() {
050        return iStartTime;
051    }
052
053    /**
054     * Get finishing time of the location (start time + operation processing
055     * time)
056     * @return finishing time of the location
057     */
058    public int getFinishingTime() {
059        return iStartTime + (variable()).getProcessingTime() - 1;
060    }
061
062    /**
063     * Start time of the location
064     */
065    @Override
066    public double toDouble() {
067        return iStartTime;
068    }
069
070    /**
071     * String representation (operation name = start time)
072     */
073    @Override
074    public String toString() {
075        return variable().getName() + "=" + iStartTime;
076    }
077
078    /**
079     * Name -- start time
080     */
081    @Override
082    public String getName() {
083        return String.valueOf(iStartTime);
084    }
085
086    /**
087     * Returns true if overlap with the given location
088     * @param anotherLocation given location
089     * @return true if overlap with the given location
090     */
091    public boolean overlap(Location anotherLocation) {
092        if (getStartTime() + variable().getProcessingTime() <= anotherLocation.getStartTime())
093            return false;
094        if (anotherLocation.getStartTime() + anotherLocation.variable().getProcessingTime() <= getStartTime())
095            return false;
096        return true;
097    }
098
099    /**
100     * Returns true if before the given location
101     * @param anotherLocation given location
102     * @return true if before the given location
103     */
104    public boolean before(Location anotherLocation) {
105        if (getStartTime() + variable().getProcessingTime() <= anotherLocation.getStartTime())
106            return true;
107        return false;
108    }
109
110    /**
111     * Returns true if after the given location
112     * @param anotherLocation given location
113     * @return true if after the given location
114     */
115    public boolean after(Location anotherLocation) {
116        return anotherLocation.before(this);
117    }
118}