StdIn,StdOut,StdRandom: https://codeshare.io/786WlD
Assignment: https://ds.cs.rutgers.edu/assignment-infinitywar/
/**
*
* Using the Adjacency Matrix of n vertices and starting from Earth (vertex 0),
* modify the edge weights using the functionality values of the vertices that each edge
* connects, and then determine the minimum cost to reach Titan (vertex n-1) from Earth (vertex 0).
*
* Steps to implement this class main method:
*
* Step 1:
* LocateTitanInputFile name is passed through the command line as args[0]
* Read from LocateTitanInputFile with the format:
* 1. g (int): number of generators (vertices in the graph)
* 2. g lines, each with 2 values, (int) generator number, (double) funcionality value
* 3. g lines, each with g (int) edge values, referring to the energy cost to travel from
* one generator to another
* Make an adjacency matrix for g generators.
*
* Populate the adjacency matrix with edge values (the energy cost to travel from one
* generator to another).
*
* Step 2:
* Update the adjacency matrix to change EVERY edge weight (energy cost) by DIVIDING it
* by the functionality of BOTH vertices (generators) that the edge points to. Then,
* typecast this number to an integer (this is done to avoid precision errors). The result
* is an adjacency matrix representing the TOTAL COSTS to travel from one generator to another.
*
* Step 3:
* LocateTitanOutputFile name is passed through the command line as args[1]
* Use Dijkstra's Algorithm to find the path of minimum cost between Earth and Titan.
* Output this number into your output file!
*
* Note: use the StdIn/StdOut libraries to read/write from/to file.
*
* To read from a file use StdIn:
* StdIn.setFile(inputfilename);
* StdIn.readInt();
* StdIn.readDouble();
*
* To write to a file use StdOut (here, minCost represents the minimum cost to
* travel from Earth to Titan):
* StdOut.setFile(outputfilename);
* StdOut.print(minCost);
*
* Compiling and executing:
* 1. Make sure you are in the ../InfinityWar directory
* 2. javac -d bin src/avengers/*.java
* 3. java -cp bin avengers/LocateTitan locatetitan.in locatetitan.out
*
*
*/
public class LocateTitan {
public static void main (String [] args) {
if ( args.length < 2 ) {
StdOut.println("Execute: java LocateTitan <INput file> <OUTput file>");
return;
}
// CODE HERE//
}
Sample run
6
0 0.5
1 0.3
2 0.2
3 0.1
4 0.9
5 0.7
0 1 4 0 0 0
1 0 4 2 7 0
4 4 0 3 5 0
0 2 3 0 4 6
0 7 5 4 0 7
0 0 0 6 7 0
sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem i
Unlock access to this and over
10,000 step-by-step explanations
Have an account? Log In