public Edge(Vertex origin, Vertex destination) : this(origin, destination, (int)com.smartcampus.baselogic.DistanceMeasurements.CalculateMoveddistanceInMeters( origin.getLocation().getAbsoluteLocation().getLatitude(), origin.getLocation().getAbsoluteLocation().getLongitude(), destination.getLocation().getAbsoluteLocation().getLatitude(), destination.getLocation().getAbsoluteLocation().getLongitude())) { }
// Copy constructor public Vertex(Vertex aVertex) { double latitude = aVertex.getLocation().getAbsoluteLocation().getLatitude(); double longitude = aVertex.getLocation().getAbsoluteLocation().getLongitude(); double altitude = aVertex.getLocation().getAbsoluteLocation().getAltitude(); AggregateLocation aggLoc = new AggregateLocation(new AbsoluteLocation(latitude, longitude, altitude)); this.location = aggLoc; this.inEdges = aVertex.getInEdges(); this.outEdges = aVertex.getOutEdges(); this.id = aVertex.getId(); this.fingerprints = aVertex.getFingerPrints(); this.radiusVertices = aVertex.getRadiusVertices(); }
public IEnumerable<Edge> addUndirectionalEdges(Vertex v1, Vertex v2) { Edge e1 = addDirectionalEdge(v1, v2); Edge e2 = addDirectionalEdge(v2, v1); List<Edge> result = new List<Edge>(); result.Add(e1); result.Add(e2); return result; }
public void setDestination(Vertex destination) { this.destination = destination; }
public bool addStaircaseVertex(Vertex v) { starcaseVertices.Add(v); return true; }
//We also add any missing vertices public Edge addDirectionalEdge(Vertex origin, Vertex destination) { Edge e = new Edge(origin, destination); return addDirectionalEdge(e); }
public bool removeUndirectionalEdges(Vertex v1, Vertex v2) { bool mod1 = removeDirectionalEdge(v1, v2); bool mod2 = removeDirectionalEdge(v2, v1); return mod1 || mod2; }
public bool removeElevatorVertex(Vertex v) { return elevatorVertices.Remove(v); }
public Vertex[] endVertices(Edge e) { Vertex[] result = new Vertex[2]; result[0] = e.getOrigin(); result[1] = e.getDestination(); return result; }
public IEnumerable<Vertex> destinations(Vertex v) { return v.destinations(); }
public int degree(Vertex v) { if (vertices.ContainsValue(v)) return v.degree(); else return -1; }
public bool ContainsVertex(Vertex v) { return vertices.ContainsKey(v.getId()); }
public bool areAdjacent(Vertex v, Vertex w) { foreach (Vertex cur in v.adjacentVertices()) if (cur.Equals(w)) return true; return false; }
public IEnumerable<Vertex> adjacentVertices(Vertex v) { return v.adjacentVertices(); }
public bool addVertex(Vertex v) { if (vertices.ContainsKey(v.getId())) return false; //Add vertex to <vertexId, vertex> structure vertices.Add(v.getId(), v); //Add vertex to <floorNum, List<Vertex> structure if (v.getLocation() != null && v.getLocation().getAbsoluteLocation() != null) { int floor = (int)v.getLocation().getAbsoluteLocation().getAltitude(); if (!verticesByFloor.ContainsKey(floor)) { verticesByFloor.Add(floor, new List<Vertex>()); } verticesByFloor[floor].Add(v); } return true; }
public IEnumerable<Edge> outEdges(Vertex v) { return v.getOutEdges(); }
public bool removeDirectionalEdge(Vertex origin, Vertex destination) { Edge e = new Edge(origin, destination); //Removes edge if present bool sourceMod = origin.removeOutEdge(destination) || destination.removeInEdge(origin); return edges.Remove(e) || sourceMod; }
public IEnumerable<Edge> incidentEdges(Vertex v) { return v.incidentEdges(); }
public bool removeStaircaseVertex(Vertex v) { return starcaseVertices.Remove(v); }
public int inDegree(Vertex v) { return v.inDegree(); }
public bool removeVertex(Vertex v) { foreach (Edge e in v.incidentEdges()) edges.Remove(e); //remove from <vertexId, vertex> structure vertices.Remove(v.getId()); //remove from <floorNum, List<Vertex> structure bool hasLocation = v.getLocation() != null && v.getLocation().getAbsoluteLocation() != null; if (hasLocation) { int floor = (int)v.getLocation().getAbsoluteLocation().getAltitude(); if (verticesByFloor.ContainsKey(floor)) { verticesByFloor[floor].Remove(v); } } return true; }
public IEnumerable<Edge> inEdges(Vertex v) { return v.getInEdges(); }
public bool addElevatorVertex(Vertex v) { elevatorVertices.Add(v); return true; }
// Methods dealing with directed edges // //Methods dealing with positioning //We don't bother to create a subclass for this behavior as our graph is only used for one purpose in this application public void InsertRadiusVertices(Vertex v, int radius) { AbsoluteLocation sourceLocation = v.getLocation().getAbsoluteLocation(); AbsoluteLocation targetLocation; double dist; foreach (Vertex w in vertices.Values) { if (v.Equals(w)) continue; targetLocation = w.getLocation().getAbsoluteLocation(); dist = com.smartcampus.baselogic.DistanceMeasurements.CalculateMoveddistanceInMeters( sourceLocation.getLatitude(), sourceLocation.getLongitude(), targetLocation.getLatitude(), targetLocation.getLongitude()); if (dist <= radius) v.addRadiusVertex((Vertex)w); } }
public Vertex Opposite(Vertex k) { if (k.Equals(origin)) return destination; else if (k.Equals(destination)) return origin; else return null; }
public Vertex opposite(Edge e, Vertex v) { return e.Opposite(v); }
public void setOrigin(Vertex origin) { this.origin = origin; }
/** * @return All vertices with an edge going to v */ public IEnumerable<Vertex> origins(Vertex v) { return v.origins(); }
public Edge(Vertex origin, Vertex destination, int distance) { this.origin = origin; this.destination = destination; this.distance = distance; }
public int outDegree(Vertex v) { return v.outDegree(); }