Project Code ----------------------------- Olex Ponomarenko ---------------------PYTHON CODE------------------------------------------- >> Road Class >> Private Data x1 y1 x2 y2 - This road is from point (x1,y1) to (x2,y2) loca - road goes from this locb - to this size - A number from 1 to 5 representing the road's size (type) type - A string name of the kind of road this is: such as "Residential", or "Interstate Highway" intersections - a list of all the intersections that are on the road >> Methods __init__(self, loca, locb, size): initiates the road from location a to location b of the given size __str__(self): internal Python method (such as Java .toString()) that returns the type of road this is intersection(self, road): returns the type of intersection (i.e. stop sign, traffic light, exit, no intersection) that should be placed between the two roads (the given and the active) equation(self) returns an equation for the road line as [m,b], from y= mx + b form. split(self,splitloc) splits the road into two subroads, one going from location a to splitloc, another from splitloc to b getRoads(self) recursively returns all subroads from this road that are created when intersections are made also self-explanatory methods .getx1,.getx2,.gety1,.gety2, .gettype, .getsize >> Location Class >> Private Data x y - This location is situated at (x,y) name - name of the intersection coords - another way of accessing the position of the location intersection - a boolean saying if this location is an intersection of two (or more) roads or not flagged - internal value used when generating the graph to flag locations on top of each other for deletion weight - weight of the location from 1-5. This is usually equal to the maximum size of roads coming out of the location. >> Methods __init__(self, sname,scoods,sintersection): constructor that initiates a location at the coordinates with the given name and boolean __str__(self): internal Python method that returns the name as well as the position of the location setCoords(self, newx,newy): changes the position of the location, keeping roads intact setWeight(self,newweight): a way to change the weight of the location manually distto(self, loc) returns the distance between the active and the given road (self and loc) disttopt(self, lx,ly) returns the distance between self and a given point (lx, ly) isbetween(self,loc1,loc2) returns a boolean saying, if the three locations (self, loc1, and loc2) are coolinear, whether self is between loc1 and loc2. also self-explanatory helper methods getCoords(self), getx(self), gety(self), getintersection(self) >> Main Program Structure test(filename, citynamefile, scale) calls the random graph generator, creates a graph, and tests it using the inputs. The output is left in the filename, and the console output recieves messages as well. >> Random Graph Generator Primary Functions makegraph(filename, citynamefile,scale) randomly generates a graph of scale number of locations on a scale x scale grid of pixels. The citynamefile is used to name locations that are created. The graph structure is then output into filename. testconnections(graph) tests whether each node of a graph is connected to each other node (checks integrity of map) connect(graph, a, b, roadsize, roadlist, roadcounter) connects a and b with a road of size roadsize, places the road into the roadlist, and adds a counter to roadcounter makerandomroad(graph, cities, roadlist, roadcounter) creates a random road between two random points in graph, updating the cities, roadlist, and roadcounter with the new road. Affected by weights of locations and such. >> Random Graph Generator Auxillary Functions closelocation(location, list, scale) Finds a location in list that is within scale /40 (within 25 pixels on a 1000 pixel board) of the given location, and returns a pointer to the location roadfromsource(graph,cities,roadlist,roadcounter,source,size): A recursive (rarely > 1) method that guarantees that there are ways of getting on highways - it is called to generate a smaller highway crossing or connecting to large 4-5 roads to ensure that they are connected to the rest of the graph (and there aren't any locations with only size 1-2 and 5 roads, which wouldn't have an intersection between them) closeindex(location, list, scale) Similar to closelocation, but returns the index of the location in the list >> Searching Functions randomtest(graph, searchtype(,loc1,loc2)) This method is the most-used test and can be set up in a for loop to develop data sets. It returns large arrays of data, including processing time, speed, etc, as well as which locations it tested. Loc1 and Loc2 are optional, and when input, the test is not random (obviously) pointcosts(...) A* search with point costs as well as normal distance* speed limit heuristics, uses pch(...) nopointcosts(...) A* with no point costs, uses controlh(...) controlh(...) Control heuristic, utilizes simple distance * speed limit weighing. Fast. pch(...) Stands for "point costs heuristic". Adds left turn delays and right turn delays based on direction. Much more complex than controlh(...), and therefore slower. (...) stands for (graph, scale, loc1, loc2, searchtype, roadlist, roadcounter, pathqueue, curloc) ---------------------- JAVA CODE ---------------------------------------- class Graphdisplay main() creates infile and outfile, prompts for different things if not provided by infile. reads in all of the infile data, creates Coords and Roads from the data. creates a new JFrame to house a GraphPanel based on the size of the data, sets the panel to visible class GraphPanel constructor( Coord[], Road[], scale ) creates a Graphics2D object, an image to draw the stuff in, calls drawAll and repaint paintComponent(Graphics g) lower level function used by repaint() internally to draw the image on the screen. it just calls g.drawImage to draw the image. drawAll( Coord[], Road [], scale ) Called at the beginning to draw all of the locations and roads on the screen. The function receives color data from coords and roads themselves. class Coord data: int[2] coords, String name constructor( int x, int y, String name ) creates an instance of the Coord class with given parameters point() returns a Rectangle2D.Double that is a 3x3 pixels rectangle around the coordinate of this instance of the Coord class. Also helper methods: toString(), x(), y(), name() class Road data: Coord p1, Coord p2, int size constructor(ints x1,y1,x2,y2, int size) creates an instance of the Road class with given parameters constructor(Coord p1, Coord p2) creates an instance of the Road class with given parameters and a default size of 2 line() returns a Line2D.Double from p1 to p2 color() returns a color from lightGray to magenta based on the road size.