001package org.cpsolver.coursett.model; 002 003import org.cpsolver.coursett.constraint.RoomConstraint; 004import org.cpsolver.ifs.util.DistanceMetric; 005 006/** 007 * Room part of placement. <br> 008 * <br> 009 * 010 * @version CourseTT 1.3 (University Course Timetabling)<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 */ 029 030public 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 * @param ignoreTooFar true if distance conflicts are to be ignored 058 * @param rc related room constraint 059 */ 060 public RoomLocation(Long id, String name, Long bldgId, int preference, int size, Double x, Double y, 061 boolean ignoreTooFar, RoomConstraint rc) { 062 iId = id; 063 iName = name; 064 iPreference = preference; 065 iRoomSize = size; 066 iPosX = x; 067 iPosY = y; 068 iBldgId = bldgId; 069 iRoomConstraint = rc; 070 iIgnoreTooFar = ignoreTooFar; 071 } 072 073 /** Room id 074 * @return room unique id 075 **/ 076 public Long getId() { 077 return iId; 078 } 079 080 /** Building id 081 * @return building unique id 082 **/ 083 public Long getBuildingId() { 084 return iBldgId; 085 } 086 087 /** Room name 088 * @return room name 089 **/ 090 public String getName() { 091 return iName; 092 } 093 094 /** Room preference 095 * @return room preference 096 **/ 097 public int getPreference() { 098 return iPreference; 099 } 100 101 /** 102 * Set room preference 103 * @param preference room preferences 104 */ 105 public void setPreference(int preference) { 106 iPreference = preference; 107 } 108 109 /** Room size 110 * @return room size 111 **/ 112 public int getRoomSize() { 113 return iRoomSize; 114 } 115 116 /** Position of the building 117 * @param x X-coordinate (latitude) 118 * @param y Y-coordinate (longitude) 119 **/ 120 public void setCoordinates(Double x, Double y) { 121 iPosX = x; 122 iPosY = y; 123 } 124 125 /** X-position of the building 126 * @return X-coordinate (latitude) 127 **/ 128 public Double getPosX() { 129 return iPosX; 130 } 131 132 /** Y-position of the building 133 * @return Y-coordinate (longitude) 134 **/ 135 public Double getPosY() { 136 return iPosY; 137 } 138 139 public boolean getIgnoreTooFar() { 140 return iIgnoreTooFar; 141 } 142 143 public RoomConstraint getRoomConstraint() { 144 return iRoomConstraint; 145 } 146 147 @Override 148 public String toString() { 149 return "Room{name=" + iName + ", pref=" + iPreference + "}"; 150 } 151 152 @Override 153 public boolean equals(Object o) { 154 if (o == null || !(o instanceof RoomLocation)) 155 return false; 156 return getId().equals(((RoomLocation) o).getId()); 157 } 158 159 public double getDistanceInMeters(DistanceMetric m, RoomLocation roomLocation) { 160 if (getId().equals(roomLocation.getId())) 161 return 0.0; 162 if (getIgnoreTooFar() || roomLocation.getIgnoreTooFar()) 163 return 0.0; 164 return m.getDistanceInMeters(getId(), getPosX(), getPosY(), roomLocation.getId(), roomLocation.getPosX(), roomLocation.getPosY()); 165 } 166 167 public int getDistanceInMinutes(DistanceMetric m, RoomLocation roomLocation) { 168 if (getId().equals(roomLocation.getId())) 169 return 0; 170 if (getIgnoreTooFar() || roomLocation.getIgnoreTooFar()) 171 return 0; 172 return m.getDistanceInMinutes(getId(), getPosX(), getPosY(), roomLocation.getId(), roomLocation.getPosX(), roomLocation.getPosY()); 173 } 174 175 @Override 176 public int compareTo(RoomLocation o) { 177 int cmp = -(new Long(getRoomSize())).compareTo(new Long(o.getRoomSize())); 178 if (cmp != 0) 179 return cmp; 180 return getName().compareTo((o).getName()); 181 } 182 183 @Override 184 public int hashCode() { 185 return getName().hashCode(); 186 } 187}