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 =-1637215435293585128L;
public Graph graph;
private List misLocations;
private ListmisEdges;
private ArrayListmisUsers;
private static LocationManager manager=null;
private static User loginUser;
public LocationManager(){
super();
graph = new Graph();
misLocations = new ArrayList<>();
misEdges= new ArrayList<>();
misUsers= new ArrayList<>();
} public static LocationManager getInstance(){
if (manager==null)
manager= new LocationManager();
return manager;
} public List getLocations(){
return misLocations;
} public Graph getGraph(){
return graph;
}public List getMisLocations(){
return misLocations;
} public void setMisLocations(List misLocations){
this.misLocations = misLocations;
} public static LocationManager getManager(){
return manager;
} public static void setManager(LocationManager manager){
LocationManager.manager = manager;
} public void setGraph(Graph graph){
this.graph = graph; }
public void agregarLocation(Location location){
misLocations.add(location);
graph.addLocation(location); }
public void agregarEdge(Edge edge){
misEdges.add(edge);
graph.addEdge(edge); }
public Location buscarLocationByCodigo(String idLocation){
Location aux = null;
boolean encontrado = false;
int i=0;
while (!encontrado && i location.getId().equals(locationId));
graph.removeLocation(locationId); // Remove from the graph.}
public void eliminarEdge(String startLocationId, String endLocationId){
misEdges.removeIf(edge -> edge.getStartLocation().getId().equals(startLocationId) && edge.getEndLocation().getId().equals(endLocationId));
graph.removeEdge(startLocationId, endLocationId); // Remove from the graph.
}
public void actualizarLocation(String id, String newName){
for (Location loc : misLocations){
if (loc.getId().equals(id)){
loc.setName(newName);
break;
}}
graph.updateLocationName(id, newName); // Update name in the graph.
}
public void actualizarEdge(String startId, String endId, float newWeight){
for (Edge edge : misEdges){
if (edge.getStartLocation().getId().equals(startId) && edge.getEndLocation().getId().equals(endId)){
edge.setWeight(newWeight);
break;
}}
graph.updateEdgeWeight(startId, endId, newWeight); // Update edge in the graph.
}public class Edge implements Serializable {
private static final long serialVersionUID =-2056167028484334079L;
private Location startLocation;
private Location endLocation;
private float weight;
private int time;
public Edge(Location start, Location end, float weight, int time){
super();
this.startLocation = start;
this.endLocation = end;
this.weight = weight;
this.time=time; (sets&gets ommited 4space)
}public class Location implements Serializable {
private static final long serialVersionUID =8486261109274250359L;
private String id;
private String name;
private ArrayList edges;
public Location(String 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 =2369466113803253034L;
private Map locations; // Mapa de ID de ubicacin a objetos Location
public Graph(){super();
locations = new HashMap<>(); } it has set&gets but theyR omitted because the space.
public void addLocation(Location location){
locations.put(location.getId(), location);
} public void removeLocation(String locationId){
locations.remove(locationId);
} public void updateLocationName(String id, String newName){
if (loc....

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!