// RoutesAndLocations.ump  Class diagram represented in Umple
//
// Author: Timothy C. Lethbridge

namespace routesAndLocations;

/* 

This file describes reusable model elements that are used in the 
bCMS Crisis Management System. It is necessary to have a rudimentary
Graphical Information System such as described in this submodel as part
of bCMS in order to plan routes and to track where crises are. This file
has the necessary classes.

*/

/* 
 * A CityMap contains the precompiled streets and landmarks
 * This must be read in from the database on system initialization
 */
class CityMap {
  singleton;
  0..1 -> * Landmark fireStn;
  0..1 -> * Landmark policeStn;
  0..1 -> * Landmark otherLm;
  0..1 -> * NamedRoad;
}
  
/*
 * A Location describes a place such as an intersection, landmark, bend in a road, etc.
 */
class Location {
  Float lattitude;
  Float longitude;
}

class Landmark {
  isA Location;
  
  // Name of landmark (name of fire station, business, address)
  description;  
  landmarkType { fireStation { } policeStation { } touristDestination { } other { } } 
}

/*
 * RoadNodes are places where RoadSegments connect. A node with just one incoming
 * and one outgoing is used to handle changes in direction, e.g. as a road turns
 * a corner, changes in speed limit, changes in number of lanes, and other factors.
 * When there is more than one outgoing or incoming, the node represents points
 * where traffic flow can split and join.
 * A crossroads is one type. Entry into a roundabout would be another,
 * Highway merges and exits are other kinds as are parking lots and entries
 * into or out of fire stations..
 *
 * RoadSegments leaving the city lead to no RoadNode
 * RoadSegments entering the city come from no RoadNode
 */
class RoadNode {
  Integer id;
   // Could be at a landmark
  0..1 -> 1 Location nodeLocation;
  0..1 end -- * RoadSegment incomingRoads;
  0..1 start -- * RoadSegment outgoingRoads;
}

class Intersection {
  isA RoadNode;
  // illegal, but possible turns for police and fire
  0..1 -> * Turn illegalTurns;
  // Impossible turns , e.g. because of barriers, turning radius
  0..1 -> * Turn impossibleTurns;
}

/* 
 * Turns are used to model illegal turns, e.g. turning left
 * when there is 'no left turn' allowed, or 'no U turn' allowed.
 */
class Turn {
  RoadSegment turnFrom;
  RoadSegment turnTo;
}

/*
 * A named road might have the name of a street, the number of
 * a highway, etc. A RoadSegment can have several names because
 * for example, sometimes several numbered highways share a segment
 */
class NamedRoad {
  name;
  
  // Most roads have two directions, e.g. North and South
  direction;  
  
  // Listed in order
  * -- 1..* RoadSegment segments; 
}
  
/*
 * A RoadSegment represents a section of road on which a vehicle can drive.
 * The ends of each segment have been modeled using RoadNodes.
 * Note that distance can be calculated from the speed limit, and locations
 */
class RoadSegment {
  Integer speedLimit;
  
  // Indicator of real-time congestion; 0=blocked
  Integer currentReportedSpeed; 
  Integer lanes;
  
  // The following are used to determine addresses
  Integer streetNumberAtStart;
  Integer streetNumberAtEnd;
  * -> * RoadSegment inverseSegments;
}

/* 
 * A route is a plan to get from one location to another
 * It is built by algorithms that traverse the nodes and arcs of the map
 * taking into account speed, congestion, etc.
 */
class Route {
   // Ordered list of segments
   0..1 -> 1..* RoadSegment;

   // Time seconds at current flow speeds
   Integer estimatedTime; 
}
//$?[End_of_model]$?

class Turn
{
  position 89 579 181 77;
}

class Intersection
{
  position.association Intersection__Turn:illegalTurns 50,46 11,0;
  position.association Intersection__Turn:impossibleTurns 80,46 110,0;
  position 100 442 109 45;
}

class Route
{
  position 372 593 175 60;
  position.association RoadSegment__Route 4,0 49,131;
}

class RoadSegment
{
  position 377 265 225 128;
  position.association RoadSegment__RoadSegment:inverseSegments 23,128 0,124;
}

class RoadNode
{
  position.association RoadNode:start__RoadSegment:outgoingRoads 170,26 0,91;
  position.association RoadNode:end__RoadSegment:incomingRoads 170,1 0,35;
    position.association Location:nodeLocation__RoadNode 163,0 118,77;
position 62 331 170 60;
}

class NamedRoad
{
  position 409 20 126 77;
  position.association NamedRoad__RoadSegment:segments 30,80 30,0;
}

class Location
{
  position 258 60 121 77;
}

class Landmark
{
  position 111 211 141 60;
}

class CityMap
{
  position.association CityMap__Landmark:fireStations 30,46 30,0;
  position.association CityMap__Landmark:policeStations 60,46 60,0;
  position.association CityMap__Landmark:otherLandmarks 60,46 60,0;
    position.association CityMap__Landmark:fireStn 5,46 0,56;
  position.association CityMap__Landmark:policeStn 72,46 60,0;
  position.association CityMap__Landmark:otherLm 25,46 0,0;
position 17 67 109 45;
}

