Skip to content

Commit

Permalink
Worksession progress
Browse files Browse the repository at this point in the history
  • Loading branch information
jakedcolbert committed May 3, 2022
1 parent a3fef01 commit 4eb83ef
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 145 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ project5: project5.cc province.cc province.h
# test the code against an expected output file
# this test should grow into a spaceship and end with blinkers
test-requirement1: project5
./project5 < test-data/requirement1.in > test-data/project5.out
diff test-data/project5.out test-data/requirement1.out > test.diff
wc -l test.diff
./project5 < test-data/t0502-combo.in > test-data/project5.out
diff test-data/project5.out test-data/shortest.out > test.diff
rm test-data/project5.out
Binary file modified project5
Binary file not shown.
22 changes: 2 additions & 20 deletions project5.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,11 @@ int main(int argc, char *argv[]) {
// create a new graph for each loop, which will read all of the
// corresponding data per graph
Province theProvince(cin);

std::cout << std::endl;
std::cout << "------------------------------------------------" << std::endl;
std::cout << "---------------- New DataSet: ------------------" << std::endl;
std::cout << "------------------------------------------------" << std::endl;
std::cout << std::endl;

theProvince.printAll(0, cout);


theProvince.printShortestPath(std::cout);

std::cout << std::endl;
std::cout << "------------------------------------------------" << std::endl;
std::cout << "------------------------------------------------" << std::endl;
std::cout << std::endl;

theProvince.minSpan(std::cout);

std::cout << std::endl;
std::cout << "------------------------------------------------" << std::endl;
std::cout << "------------------------------------------------" << std::endl;
std::cout << std::endl;

std::cout << "------------------------------------------------------------------";
std::cout << endl;
}
}
20 changes: 9 additions & 11 deletions province.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,20 @@ void Province::printAll(int start, std::ostream & output) {
queue <int> toVisit; // use queue to keep track of which town to visit next
toVisit.push(start);
scheduled[start] = true;
output << "The input data is :" << endl << endl;
output << "The input data is:" << endl << endl;

// Visit every town in the queue
while (!toVisit.empty()) {
int current = toVisit.front();
toVisit.pop();

output << " ";
output << _towns[current]._name << endl;

// Add current town's(vertex's) unscheduled neighbors to the queue
for (Town::RoadList::iterator neighbor = _towns[current]._roads.begin();
neighbor != _towns[current]._roads.end(); neighbor++) {
std::string neighborName = _towns[neighbor->_head]._name;

output << " ";
output << neighborName << " " << neighbor->_length << " mi";
output << " " << neighborName << " " << neighbor->_length << " mi";

// if the type is bridge, then add to output
if (neighbor ->_isBridge) {
Expand All @@ -113,7 +110,7 @@ void Province::printAll(int start, std::ostream & output) {
}
}
}
output << endl << endl;
output << endl;
}

int Province::smallest(double dist[], std::list <int> toVisit,
Expand Down Expand Up @@ -147,7 +144,7 @@ void Province::printShortestPath(std::ostream & output) const {
return;
}

output << "The shortest routes from " + _towns[0]._name;
output << "The shortest paths from " + _towns[0]._name;
output << " are:" << std::endl << std::endl;

// keeps track of the index of the predecessor to each
Expand Down Expand Up @@ -194,7 +191,7 @@ void Province::printShortestPath(std::ostream & output) const {

// print out the data for each non capital town
for (int i = 1; i < _numberOfTowns; i++) {
output << " " << "The shortest route from " + _towns[0]._name;
output << " " << "The shortest path from " + _towns[0]._name;
output << " to " + _towns[i]._name + " is " << dist[i];
output << " mi:" << std::endl;

Expand All @@ -214,11 +211,12 @@ void Province::printShortestPath(std::ostream & output) const {

// print out the names for each entry in the stack
while (!predecessors.empty()) {
output << " " << _towns[predecessors.top()]._name;
output << " " << _towns[predecessors.top()]._name;
output << std::endl;
predecessors.pop();
}
}
cout << endl;
}

/**
Expand Down Expand Up @@ -308,11 +306,11 @@ void Province::minSpan(std::ostream & output) const {
}

output << "The road upgrading goal can be achieved at minimal cost by upgrading:";
output << std::endl << std::endl;
output << std::endl;

// Print names of towns in minimum spanning tree of province
for (int i = 0; i < minSpanTree.size(); i++) {
output << " ";
output << " ";
output << _towns[minSpanTree[i]._head]._name;
output << " to ";
output << _towns[minSpanTree[i]._tail]._name << std::endl;
Expand Down
102 changes: 30 additions & 72 deletions test-data/project5.out
Original file line number Diff line number Diff line change
@@ -1,84 +1,42 @@
The input data is:

------------------------------------------------
---------------- New DataSet: ------------------
------------------------------------------------
Wenham
Hamilton 1 mi
Hamilton
Wenham 1 mi

The input data is :
The shortest paths from Wenham are:

Salem
Beverly 2.4 mi via bridge
Danvers 3.7 mi via bridge
Lynn 4.9 mi
Beverly
Danvers 2.9 mi
Salem 2.4 mi via bridge
Wenham 5.2 mi
Danvers
Beverly 2.9 mi
Wenham 4.2 mi
Salem 3.7 mi via bridge
Lynn
Salem 4.9 mi
Wenham
Beverly 5.2 mi
Danvers 4.2 mi


The shortest routes from Salem are:

The shortest route from Salem to Wenham is 7.6 mi:
Salem
Beverly
Wenham
The shortest route from Salem to Beverly is 2.4 mi:
Salem
Beverly
The shortest route from Salem to Danvers is 3.7 mi:
Salem
Danvers
The shortest route from Salem to Lynn is 4.9 mi:
Salem
Lynn

------------------------------------------------
------------------------------------------------
The shortest path from Wenham to Hamilton is 1 mi:
Wenham
Hamilton

The road upgrading goal can be achieved at minimal cost by upgrading:
Hamilton to Wenham

Salem to Beverly
Danvers to Beverly
Wenham to Danvers
Salem to Lynn

------------------------------------------------
------------------------------------------------

------------------------------------------------------------------
The input data is:

------------------------------------------------
---------------- New DataSet: ------------------
------------------------------------------------
A
B 1 mi via bridge
B
A 1 mi via bridge
C 1 mi via bridge
C
B 1 mi via bridge

The input data is :
The shortest paths from A are:

Wenham
Hamilton 1 mi
Hamilton
Wenham 1 mi


The shortest routes from Wenham are:

The shortest route from Wenham to Hamilton is 1 mi:
Wenham
Hamilton

------------------------------------------------
------------------------------------------------
The shortest path from A to B is 1 mi:
A
B
The shortest path from A to C is 2 mi:
A
B
C

The road upgrading goal can be achieved at minimal cost by upgrading:
B to A
C to B

Hamilton to Wenham

------------------------------------------------
------------------------------------------------

------------------------------------------------------------------
39 changes: 0 additions & 39 deletions test-data/requirement1.out

This file was deleted.

45 changes: 45 additions & 0 deletions test-data/shortest.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
The input data is:

Wenham
Hamilton 1 mi
Hamilton
Wenham 1 mi

The shortest paths from Wenham are:

The shortest path from Wenham to Hamilton is 1 mi:
Wenham
Hamilton

The road upgrading goal can be achieved at minimal cost by upgrading:
Hamilton to Wenham


------------------------------------------------------------------

The input data is:

A
B 1 mi via bridge
B
A 1 mi via bridge
C 1 mi via bridge
C
B 1 mi via bridge

The shortest paths from A are:

The shortest path from A to B is 1 mi:
A
B
The shortest path from A to C is 2 mi:
A
B
C

The road upgrading goal can be achieved at minimal cost by upgrading:
B to A
C to B


------------------------------------------------------------------

0 comments on commit 4eb83ef

Please sign in to comment.