001    package net.sf.cpsolver.coursett.model;
002    
003    import net.sf.cpsolver.coursett.constraint.RoomConstraint;
004    
005    /**
006     * Room part of placement.
007     * <br><br>
008     *
009     * @version
010     * CourseTT 1.1 (University Course Timetabling)<br>
011     * Copyright (C) 2006 Tomáš Müller<br>
012     * <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
013     * Lazenska 391, 76314 Zlin, Czech Republic<br>
014     * <br>
015     * This library is free software; you can redistribute it and/or
016     * modify it under the terms of the GNU Lesser General Public
017     * License as published by the Free Software Foundation; either
018     * version 2.1 of the License, or (at your option) any later version.
019     * <br><br>
020     * This library is distributed in the hope that it will be useful,
021     * but 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.
024     * <br><br>
025     * You should have received a copy of the GNU Lesser General Public
026     * License along with this library; if not, write to the Free Software
027     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
028     */
029    
030    public class RoomLocation implements Comparable {
031        private int iPreference;
032        private String iName;
033        private Long iId;
034        private Long iBldgId;
035        private int iRoomSize;
036        private int iPosX = 0, iPosY = 0;
037        private RoomConstraint iRoomConstraint = null;
038        private boolean iIgnoreTooFar = false;
039        
040        /** Constructor
041         * @param id room id
042         * @param name room name
043         * @param bldgId building id
044         * @param preference soft preference
045         * @param size room size
046         * @param x x-position of the building
047         * @param y y-position of the building
048         */
049        public RoomLocation(Long id, String name, Long bldgId, int preference, int size, int x, int y, boolean ignoreTooFar, RoomConstraint rc) {
050            iId = id;
051            iName = name;
052            iPreference = preference;
053            iRoomSize = size;
054            iPosX = x; iPosY = y;
055            iBldgId = bldgId;
056            iRoomConstraint = rc;
057            iIgnoreTooFar = ignoreTooFar;
058        }
059        
060        /** Room id */
061        public Long getId() { return iId; }
062        /** Building id */
063        public Long getBuildingId() { return iBldgId; }
064        /** Room name */
065        public String getName() { return iName; }
066        /** Room preference */
067        public int getPreference() { return iPreference; }
068        public void setPreference(int preference) { iPreference = preference; }
069        /** Room size */
070        public int getRoomSize() { return iRoomSize; }
071        /** Position of the building */
072        public void setCoordinates(int x, int y) { iPosX=x; iPosY=y; }
073        /** X-position of the building */
074        public int getPosX() { return iPosX; }
075        /** Y-position of the building */
076        public int getPosY() { return iPosY; }
077        public boolean getIgnoreTooFar() { return iIgnoreTooFar; }
078        public RoomConstraint getRoomConstraint() { return iRoomConstraint; }
079        
080        public String toString() {
081            return "Room{name="+iName+", pref="+iPreference+"}";
082        }
083        public boolean equals(Object o) {
084            if (o==null || !(o instanceof RoomLocation)) return false;
085            return getId().equals(((RoomLocation)o).getId());
086        }
087        public double getDistance(RoomLocation roomLocation) {
088            if (getId().equals(roomLocation.getId())) return 0.0;
089            if (getIgnoreTooFar() || roomLocation.getIgnoreTooFar()) return 0.0;
090            if (getPosX()<0 || getPosY()<0 || roomLocation.getPosX()<0 || roomLocation.getPosY()<0) return 10000.0;
091                    long x = getPosX()-roomLocation.getPosX();
092                    long y = getPosY()-roomLocation.getPosY();
093                    return Math.sqrt((x*x)+(y*y));
094        }
095        
096        public int compareTo(Object o) {
097            int cmp = -(new Long(getRoomSize())).compareTo(new Long(((RoomLocation)o).getRoomSize()));
098            if (cmp!=0) return cmp;
099            return getName().compareTo(((RoomLocation)o).getName());
100        }
101        
102        public int hashCode() {
103            return getName().hashCode();
104        }
105    }