001    package net.sf.cpsolver.coursett.model;
002    
003    import net.sf.cpsolver.coursett.constraint.RoomConstraint;
004    import net.sf.cpsolver.ifs.util.DistanceMetric;
005    
006    /**
007     * Room part of placement. <br>
008     * <br>
009     * 
010     * @version CourseTT 1.2 (University Course Timetabling)<br>
011     *          Copyright (C) 2006 - 2010 Tomas Muller<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     */
029    
030    public class RoomLocation implements Comparable<RoomLocation> {
031        private int iPreference;
032        private String iName;
033        private Long iId;
034        private Long iBldgId;
035        private int iRoomSize;
036        private Double iPosX = null, iPosY = null;
037        private RoomConstraint iRoomConstraint = null;
038        private boolean iIgnoreTooFar = false;
039    
040        /**
041         * Constructor
042         * 
043         * @param id
044         *            room id
045         * @param name
046         *            room name
047         * @param bldgId
048         *            building id
049         * @param preference
050         *            soft preference
051         * @param size
052         *            room size
053         * @param x
054         *            x-position of the building
055         * @param y
056         *            y-position of the building
057         */
058        public RoomLocation(Long id, String name, Long bldgId, int preference, int size, Double x, Double y,
059                boolean ignoreTooFar, RoomConstraint rc) {
060            iId = id;
061            iName = name;
062            iPreference = preference;
063            iRoomSize = size;
064            iPosX = x;
065            iPosY = y;
066            iBldgId = bldgId;
067            iRoomConstraint = rc;
068            iIgnoreTooFar = ignoreTooFar;
069        }
070    
071        /** Room id */
072        public Long getId() {
073            return iId;
074        }
075    
076        /** Building id */
077        public Long getBuildingId() {
078            return iBldgId;
079        }
080    
081        /** Room name */
082        public String getName() {
083            return iName;
084        }
085    
086        /** Room preference */
087        public int getPreference() {
088            return iPreference;
089        }
090    
091        public void setPreference(int preference) {
092            iPreference = preference;
093        }
094    
095        /** Room size */
096        public int getRoomSize() {
097            return iRoomSize;
098        }
099    
100        /** Position of the building */
101        public void setCoordinates(Double x, Double y) {
102            iPosX = x;
103            iPosY = y;
104        }
105    
106        /** X-position of the building */
107        public Double getPosX() {
108            return iPosX;
109        }
110    
111        /** Y-position of the building */
112        public Double getPosY() {
113            return iPosY;
114        }
115    
116        public boolean getIgnoreTooFar() {
117            return iIgnoreTooFar;
118        }
119    
120        public RoomConstraint getRoomConstraint() {
121            return iRoomConstraint;
122        }
123    
124        @Override
125        public String toString() {
126            return "Room{name=" + iName + ", pref=" + iPreference + "}";
127        }
128    
129        @Override
130        public boolean equals(Object o) {
131            if (o == null || !(o instanceof RoomLocation))
132                return false;
133            return getId().equals(((RoomLocation) o).getId());
134        }
135    
136        public double getDistanceInMeters(DistanceMetric m, RoomLocation roomLocation) {
137            if (getId().equals(roomLocation.getId()))
138                return 0.0;
139            if (getIgnoreTooFar() || roomLocation.getIgnoreTooFar())
140                return 0.0;
141            return m.getDistanceInMeters(getId(), getPosX(), getPosY(), roomLocation.getId(), roomLocation.getPosX(), roomLocation.getPosY());
142        }
143    
144        public int getDistanceInMinutes(DistanceMetric m, RoomLocation roomLocation) {
145            if (getId().equals(roomLocation.getId()))
146                return 0;
147            if (getIgnoreTooFar() || roomLocation.getIgnoreTooFar())
148                return 0;
149            return  m.getDistanceInMinutes(getId(), getPosX(), getPosY(), roomLocation.getId(), roomLocation.getPosX(), roomLocation.getPosY());
150        }
151    
152        @Override
153        public int compareTo(RoomLocation o) {
154            int cmp = -(new Long(getRoomSize())).compareTo(new Long(o.getRoomSize()));
155            if (cmp != 0)
156                return cmp;
157            return getName().compareTo((o).getName());
158        }
159    
160        @Override
161        public int hashCode() {
162            return getName().hashCode();
163        }
164    }