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