Question: Help with my Java route management system. The idea is to create a CRUD to edit the components of the undirected graph inserted by the
Help with my Java route management system. The idea is to create a CRUD to edit the components of the undirected graph inserted by the user. That is the idea is for them to provide the weight, time of the edges, and the names of the vertices, and a graph can be formed. I already have methods for that in my controlling class location manager and other classes called edge, location, and graph Each location will be represented as a node in a graph, and the connections between locations will be modeled as edges I will try to insert them so you have an idea of the plan. Now, based on that, I want to build a Dijkstra algorithm that serves me to calculate the shortest route between two specific locations, can you help me please?
public class LocationManager implements Serializable
private static final long serialVersionUID L;
public Graph graph;
private List misLocations;
private ListmisEdges;
private ArrayListmisUsers;
private static LocationManager managernull;
private static User loginUser;
public LocationManager
super;
graph new Graph;
misLocations new ArrayList;
misEdges new ArrayList;
misUsers new ArrayList;
public static LocationManager getInstance
if managernull
manager new LocationManager;
return manager;
public List getLocations
return misLocations;
public Graph getGraph
return graph;
public List getMisLocations
return misLocations;
public void setMisLocationsList misLocations
this.misLocations misLocations;
public static LocationManager getManager
return manager;
public static void setManagerLocationManager manager
LocationManager.manager manager;
public void setGraphGraph graph
this.graph graph;
public void agregarLocationLocation location
misLocations.addlocation;
graph.addLocationlocation;
public void agregarEdgeEdge edge
misEdges.addedge;
graph.addEdgeedge;
public Location buscarLocationByCodigoString idLocation
Location aux null;
boolean encontrado false;
int i;
while encontrado && i location.getIdequalslocationId;
graph.removeLocationlocationId; Remove from the graph.
public void eliminarEdgeString startLocationId, String endLocationId
misEdges.removeIfedge edge.getStartLocationgetIdequalsstartLocationId && edge.getEndLocationgetIdequalsendLocationId;
graph.removeEdgestartLocationId endLocationId; Remove from the graph.
public void actualizarLocationString id String newName
for Location loc : misLocations
if locgetIdequalsid
loc.setNamenewName;
break;
graph.updateLocationNameid newName; Update name in the graph.
public void actualizarEdgeString startId, String endId, float newWeight
for Edge edge : misEdges
if edgegetStartLocationgetIdequalsstartId && edge.getEndLocationgetIdequalsendId
edge.setWeightnewWeight;
break;
graph.updateEdgeWeightstartId endId, newWeight; Update edge in the graph.
public class Edge implements Serializable
private static final long serialVersionUID L;
private Location startLocation;
private Location endLocation;
private float weight;
private int time;
public EdgeLocation start, Location end, float weight, int time
super;
this.startLocation start;
this.endLocation end;
this.weight weight;
this.timetime; sets&gets ommited space
public class Location implements Serializable
private static final long serialVersionUID L;
private String id;
private String name;
private ArrayList edges;
public LocationString id String name, ArrayList edges
super;
this.id id;
this.name name;
this.edges edges;
it has set&gets but theyR omitted because the space.
public class Graph implements Serializable
private static final long serialVersionUID L;
private Map locations; Mapa de ID de ubicacin a objetos Location
public Graphsuper;
locations new HashMap; it has set&gets but theyR omitted because the space.
public void addLocationLocation location
locations.putlocationgetId location;
public void removeLocationString locationId
locations.removelocationId;
public void updateLocationNameString id String newName
if loc
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
