    001package net.sf.cpsolver.ifs.example.jobshop;
    002
    003import net.sf.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.2 (Iterative Forward Search)<br>
    011 *          Copyright (C) 2006 - 2010 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     */
    048    public int getStartTime() {
    049        return iStartTime;
    050    }
    051
    052    /**
    053     * Get finishing time of the location (start time + operation processing
    054     * time)
    055     */
    056    public int getFinishingTime() {
    057        return iStartTime + (variable()).getProcessingTime() - 1;
    058    }
    059
    060    /**
    061     * Start time of the location
    062     */
    063    @Override
    064    public double toDouble() {
    065        return iStartTime;
    066    }
    067
    068    /**
    069     * String representation (operation name = start time)
    070     */
    071    @Override
    072    public String toString() {
    073        return variable().getName() + "=" + iStartTime;
    074    }
    075
    076    /**
    077     * Name -- start time
    078     */
    079    @Override
    080    public String getName() {
    081        return String.valueOf(iStartTime);
    082    }
    083
    084    /**
    085     * Returns true if overlap with the given location
    086     */
    087    public boolean overlap(Location anotherLocation) {
    088        if (getStartTime() + variable().getProcessingTime() <= anotherLocation.getStartTime())
    089            return false;
    090        if (anotherLocation.getStartTime() + anotherLocation.variable().getProcessingTime() <= getStartTime())
    091            return false;
    092        return true;
    093    }
    094
    095    /**
    096     * Returnts true if before the given location
    097     */
    098    public boolean before(Location anotherLocation) {
    099        if (getStartTime() + variable().getProcessingTime() <= anotherLocation.getStartTime())
    100            return true;
    101        return false;
    102    }
    103
    104    /**
    105     * Returnts true if after the given location
    106     */
    107    public boolean after(Location anotherLocation) {
    108        return anotherLocation.before(this);
    109    }
    110}