Skip to content

Commit 6f795a3

Browse files
author
Joshua Caron
committed
Finished project 3
1 parent eff97ab commit 6f795a3

21 files changed

+1388
-0
lines changed

project3/1/README.txt

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
CONTENTS
2+
========
3+
* graph-service
4+
* log.txt
5+
* service.jar
6+
* src/
7+
* graph-service-test/
8+
* README.txt
9+
10+
graph-service
11+
-------------
12+
Executable shell script for task 1 of project 3.
13+
Usage: ./graph-service &
14+
15+
log.txt
16+
-------
17+
Included log file for standard error outputs generated by graph-service.
18+
Errors can be caused by malformed XML that the parser cannot read. These
19+
errors do not affect the behavior of graph-service. They cannot be suppressed,
20+
so they are redirected so as to not affect the user running the graph-service.
21+
22+
service.jar
23+
-----------
24+
Exectuable jar file used for task 1.
25+
26+
src/
27+
----
28+
Contains the source code used to compile the executable for task 1.
29+
30+
graph-service-test/
31+
-------------------
32+
Contains the tests for task 1.
33+
34+
README.txt
35+
----------
36+
This.

project3/1/graph-service

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#! /bin/sh
2+
java -jar service.jar &> log.txt
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<new low="0.0" high="5.0" />
2+
<edges>
3+
<graph low="1.0" high="5.0">
4+
<edge from="a" to="b" cost="3.0" />
5+
<edge from="b" to="c" cost="2.0" />
6+
</graph>
7+
<graph low="2.0" high="3.0">
8+
</graph>
9+
</edges>
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<add from="a" to="b" cost="8.0">
2+
<graph low="1.0" high="10.0">
3+
<edge to="c" from="a" cost="2.0" />
4+
<edge to="b" from="c" cost="3.0" />
5+
</graph>
6+
</add>
7+
8+
<add from="a" to="b" cost="1.0">
9+
<graph low="1.0" high="10.0">
10+
<edge to="c" from="a" cost="2.0" />
11+
<edge to="b" from="c" cost="3.0" />
12+
</graph>
13+
</add>
14+
15+
<edges>
16+
<graph low="1.0" high="10.0">
17+
<edge to="c" from="a" cost="2.0" />
18+
<edge to="b" from="c" cost="3.0" />
19+
<edge to="b" from="a" cost="1.0" />
20+
</graph>
21+
</edges>
22+
23+
<nodes>
24+
<graph low="1.0" high="10.0">
25+
<edge to="c" from="a" cost="2.0" />
26+
<edge to="b" from="c" cost="3.0" />
27+
<edge to="b" from="a" cost="1.0" />
28+
</graph>
29+
</nodes>
+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<join>
2+
<graph low="1.0" high="5.0">
3+
<edge from="a" to="b" cost="3.0" />
4+
<edge from="c" to="b" cost="3.0" />
5+
</graph>
6+
<graph low="2.0" high="3.0">
7+
</graph>
8+
</join>
9+
10+
<join>
11+
<graph low="1.0" high="5.0">
12+
<edge from="a" to="b" cost="3.0" />
13+
<edge from="c" to="b" cost="3.0" />
14+
</graph>
15+
<graph low="1.0" high="5.0">
16+
<edge from="e" to="d" cost="4.0" />
17+
<edge from="d" to="f" cost="1.0" />
18+
<edge from="f" to="e" cost="3.14" />
19+
</graph>
20+
</join>
21+
22+
<add from="d" to="c" cost="2.2">
23+
<graph low="1.0" high="5.0">
24+
<edge from="a" to="b" cost="3.0" />
25+
<edge from="c" to="b" cost="3.0" />
26+
<edge from="e" to="d" cost="4.0" />
27+
<edge from="d" to="f" cost="1.0" />
28+
<edge from="f" to="e" cost="3.14" />
29+
</graph>
30+
</add>
31+
32+
<path from="f" to="b">
33+
<graph low="1.0" high="5.0">8
34+
<edge from="a" to="b" cost="3.0" />
35+
<edge from="c" to="b" cost="3.0" />
36+
<edge from="e" to="d" cost="4.0" />
37+
<edge from="d" to="f" cost="1.0" />
38+
<edge from="f" to="e" cost="3.14" />
39+
<edge from="d" to="c" cost="2.2" />
40+
</graph>
41+
</path>
42+
43+
<path from="f" to="a">
44+
<graph low="1.0" high="5.0">8
45+
<edge from="a" to="b" cost="3.0" />
46+
<edge from="c" to="b" cost="3.0" />
47+
<edge from="e" to="d" cost="4.0" />
48+
<edge from="d" to="f" cost="1.0" />
49+
<edge from="f" to="e" cost="3.14" />
50+
<edge from="d" to="c" cost="2.2" />
51+
</graph>
52+
</path>
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<graph low="0.0" high="5.0" />
2+
<error msg="Something about too many arguments" />
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<error msg="Something about triangular inequality." />
2+
<graph low="1.0" high="10.0">
3+
<edge to="a" from="c" cost="2.0" />
4+
<edge to="b" from="c" cost="3.0" />
5+
<edge to="a" from="b" cost="1.0" />
6+
</graph>
7+
8+
<edges>
9+
<edge to="c" from="a" cost="2.0" />
10+
<edge to="b" from="c" cost="3.0" />
11+
<edge to="b" from="a" cost="1.0" />
12+
</edges>
13+
14+
<nodes>
15+
<node name="a" />
16+
<node name="b" />
17+
<node name="c" />
18+
</nodes>
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<error msg="Something about cost interval" />
2+
3+
<graph low="1.0" high="5.0">
4+
<edge from="a" to="b" cost="3.0" />
5+
<edge from="c" to="b" cost="3.0" />
6+
<edge from="e" to="d" cost="4.0" />
7+
<edge from="d" to="f" cost="1.0" />
8+
<edge from="f" to="e" cost="3.14" />
9+
</graph>
10+
11+
<graph low="1.0" high="5.0">8
12+
<edge from="a" to="b" cost="3.0" />
13+
<edge from="c" to="b" cost="3.0" />
14+
<edge from="e" to="d" cost="4.0" />
15+
<edge from="d" to="f" cost="1.0" />
16+
<edge from="f" to="e" cost="3.14" />
17+
<edge from="d" to="c" cost="2.2" />
18+
</graph>
19+
20+
<path cost="12.34">
21+
<edge from="f" to="e" cost="3.14" />
22+
<edge from="e" to="d" cost="4.0" />
23+
<edge from="d" to="c" cost="2.2" />
24+
<edge from="b" to="c" cost="3.0" />
25+
</path>
26+
27+
<false />

project3/1/log.txt

Whitespace-only changes.

project3/1/service.jar

14.5 KB
Binary file not shown.

project3/1/src/Edge.java

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Represents an Edge between nodes with a given cost in this graph
2+
public class Edge {
3+
Node from;
4+
Node to;
5+
Double cost;
6+
Edge(Node from, Node to, Double cost) {
7+
this.from = from;
8+
this.to = to;
9+
this.cost = cost;
10+
}
11+
12+
Node getOrigin() {
13+
return this.from;
14+
}
15+
16+
Node getDest() {
17+
return this.to;
18+
}
19+
20+
Double getCost() {
21+
return this.cost;
22+
}
23+
}

project3/1/src/Graph.java

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import java.util.Vector;
2+
3+
public interface Graph
4+
{
5+
// Set the cost interval of the graph. NOTE: Also implement this functionality
6+
// into the constructor of the Graph class
7+
void setCostInterval(Double low, Double high);
8+
9+
// Get the low cost interval for this graph.
10+
// Throw a NullPointerException if this has not been set.
11+
Double getLowCostInterval();
12+
13+
// Get the high cost interval for this graph.
14+
// Throw a NullPointerException if this has not been set.
15+
Double getHighCostInterval();
16+
17+
// Join two graphs IF they have the same cost interval and disjointed set of
18+
// nodes. Throw IllegalArgumentException w/ text if these aren't met.
19+
Graph joinGraph(Graph obj);
20+
21+
// Calculate the path between two given nodes. If no path can be found,
22+
// return null. Throw IllegalArgumentException if nodes are not in graph.
23+
Path calculatePath(Node from, Node to);
24+
25+
// Determines if a path exists between the two given nodes
26+
// Throws IllegalArgumentException if nodes don't exist in the graph.
27+
Boolean pathExists(Node from, Node to);
28+
29+
// Return shortest path between two nodes.
30+
// Throw IllegalArgumentException if nodes don't exist in the graph.
31+
Double pathDistance(Node from, Node to);
32+
33+
// Add an edge to the graph. Add nodes to graph if they don't already exist.
34+
// Throw IllegalArgumentException if triangle inequality is violated.
35+
void addEdge(String fromNode, String toNode, Double cost);
36+
37+
// Does the graph contain the given Node?
38+
boolean hasNode(String label);
39+
40+
// Get the node that has the given label
41+
Node getNode(String label);
42+
43+
// Adds a node to this graph with the given label
44+
void addNode(String label);
45+
46+
// Returns all the edges that this graph contains
47+
Vector<Edge> getEdges();
48+
49+
// Returns all the nodes associated with this graph
50+
Vector<Node> getNodes();
51+
}

0 commit comments

Comments
 (0)