#need help with a graphs project, it's due in less than 12 hours and I'm very desperate

1 messages · Page 1 of 1 (latest)

hushed wyvernBOT
#

<@&987246452180930620> please have a look, thanks.

#

Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#

a discussion about your graphs project. However, as an AI text-based assistant, I can still try my best to help you with your project.

Please provide more details about the specific problem or task you are facing with your graphs project. What kind of graphs are you working with? What do you need assistance with? The more information you provide, the better I can assist you.

heady copper
#

In need to implement the Prim algorithm to find the Minimum Spanning Tree

heady copper
#

Please can I speak with someone?

random cobalt
#

it's better to share some code, and explain where you're stuck

heady copper
#

It's a whole project basically my friends wrote the code of reading the data and creating the graphs and now I have to find the MST but I'm terrible at java and get super confused

#

I guess what I really need help with is understanding Java

subtle trail
#

rip

#

fallen soldier

hollow valley
random cobalt
#

What don't you understand? I am fine with answering some questions, but it sounds like this is a long running project given your partners code?

heady copper
heady copper
#

It's just about graphs and manipulating them

#

We read data from files

#

create graphs with that data

#

and then manipulate them

random cobalt
#

Long running as in your partner has worked on it for a decent number of time

heady copper
#

Not really either , just a couple of hours

heady copper
#

would probably be a quick help

random cobalt
#

Already doing some other things, just share where you're stuck.

heady copper
#

import Data.Distance;
import Data.Local;
import Graph.map.MapGraph;
import Graph.matrix.MatrixGraph;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

public class Read {

private final MatrixGraph<Local, Float> matrixGraphBasket = new MatrixGraph<>(false);
ArrayList<Distance> distanceList = new ArrayList<>();
ArrayList<Local> localList = new ArrayList<>();

public ArrayList<Distance> readDistance() { // O(N)
    try {
        FileReader file = new FileReader("ESINF/Files/Grafos/Small/distancias_small.csv");  // O(1)
        BufferedReader readFromFile = new BufferedReader(file);  // O(1)
        String line;  // O(1)
        String[] lineDivided;  // O(1)
        readFromFile.readLine();  // O(1)

        while ((line = readFromFile.readLine()) != null) {  // O(N)
            line = line.replaceAll("\"\"", "");  // O(3), onde M é o comprimento da linha = 3
            lineDivided = line.split(",");  // O(3)
            Distance distancia = new Distance(lineDivided[0], lineDivided[1], Float.parseFloat(lineDivided[2]));  // O(3)
            distanceList.add(distancia);  // O(1)
        }
    } catch (IOException e) {  // O(1)
        System.out.println("Erro na leitura do ficheiro");  // O(1)
    }
    return distanceList;  // O(1)
}


public ArrayList<Local> readLocal() {
    try {
        FileReader file = new FileReader("ESINF/Files/Grafos/Small/locais_small.csv");  // O(1)
        BufferedReader readFromFile = new BufferedReader(file);  // O(1)
        String line;  // O(1)
        String[] lineDivided;  // O(1)
        readFromFile.readLine();  // O(1)

        while ((line = readFromFile.readLine()) != null) {  // O(N)
            lineDivided = line.split(",");  // O(3), onde 3 é o comprimento da linha
            Local local = new Local(lineDivided[0], Float.parseFloat(lineDivided[1]), Float.parseFloat(lineDivided[2]));  // O(3)
            localList.add(local);  // O(1)
        }
    } catch (IOException e) {  // O(1)
        System.out.println("Erro na leitura do ficheiro");  // O(1)
    }
    return localList;  // O(1)
}


public MatrixGraph<Local, Float> fillInMapGraph(ArrayList<Local> localList, ArrayList<Distance> distanceList) {
    for (Local local1 : localList) {  // O(N)
        if (!matrixGraphBasket.validVertex(local1)) {  // O(V)
            matrixGraphBasket.addVertex(local1);  // O(V^2)
        }
        for (Distance distance : distanceList) {  // O(N)
            if (distance.getLocId1().equals(local1.getLocId())) {  // O(1)
                for (Local local2 : localList) {  // O(N)
                    if (distance.getLocId2().equals(local2.getLocId())) {  // O(1)
                        matrixGraphBasket.addEdge(local1, local2, distance.getLength());  // O(1)
                    }
                }
            }
        }
    }
    return matrixGraphBasket;  // O(1)
}

public MatrixGraph<Local, Float> getMatrixGraphBasket() {
    return matrixGraphBasket;
}

public ArrayList<Distance> getDistanceList() {
    return distanceList;
}
public ArrayList<Local> getLocalList() {
    return localList;
}

}

then we use that class to create the matrix graph

#

I wanna know how, from having the matrix graph I can get the MST

random cobalt
#

But where are you stuck? cfr This is not a code-writing service, we do not do your homework for you - instead, we will help you solve it yourself