Skip to content

Commit

Permalink
current progress
Browse files Browse the repository at this point in the history
  • Loading branch information
jakedcolbert committed May 5, 2022
1 parent fcfdad0 commit 574c828
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 281 deletions.
20 changes: 0 additions & 20 deletions .vscode/c_cpp_properties.json

This file was deleted.

19 changes: 0 additions & 19 deletions .vscode/launch.json

This file was deleted.

109 changes: 0 additions & 109 deletions .vscode/settings.json

This file was deleted.

33 changes: 10 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,62 +19,49 @@ project5: project5.cc province.cc province.h
g++ -std=c++11 -o project5 project5.cc province.cc

# test all the code
test-all: project5 test-nowhere test-one-road test-simple test-local test-combo
@echo ""
@echo "$(GREEN)Passed all tests!$(RESET)"
@echo ""
test-all: project5 test-requirement1 test-nowhere test-one-road test-simple test-local test-combo
@rm test.diff && rm test-data/project5.out

test: project5
./project5 < test-data/t0502-combo.in > test-data/project5.out
diff test-data/project5.out test-data/shortest.out > test.diff
rm test.diff && rm project5.out
test-requirement1: project5
./project5 < test-data/requirement1.in > test-data/project5.out
-@diff test-data/project5.out test-data/requirement1.out > test.diff && echo "$(GREEN)Passed!$(RESET)"

# test the code against an expected output file
test-nowhere: project5
@echo ""
@echo "$(RED)--- Nowhere Test ---$(RESET)"
@echo ""
./project5 < test-data/t01-nowhere.in > test-data/project5.out
diff test-data/project5.out test-data/t01-nowhere.out > test.diff
rm test.diff && rm project5.out
@echo "$(GREEN)Passed!$(RESET)"
-@diff test-data/project5.out test-data/t01-nowhere.out > test.diff && echo "$(GREEN)Passed!$(RESET)"

# test the code against an expected output file
test-one-road: project5
@echo ""
@echo "$(RED)--- One Road Test ---$(RESET)"
@echo ""
./project5 < test-data/t02-one-road.in > test-data/project5.out
diff test-data/project5.out test-data/t02-one-road.out > test.diff
rm test.diff && rm project5.out
@echo "$(GREEN)Passed!$(RESET)"
-@diff test-data/project5.out test-data/t02-one-road.out > test.diff && echo "$(GREEN)Passed!$(RESET)"

# test the code against an expected output file
test-simple: project5
@echo ""
@echo "$(RED)--- Simple Test ---$(RESET)"
@echo ""
./project5 < test-data/t03-simple.in > test-data/project5.out
diff test-data/project5.out test-data/t03-simple.out > test.diff
rm test.diff && rm project5.out
@echo "$(GREEN)Passed!$(RESET)"
-@diff test-data/project5.out test-data/t03-simple.out > test.diff && echo "$(GREEN)Passed!$(RESET)"

# test the code against an expected output file
test-local: project5
@echo ""
@echo "$(RED)--- Local Test ---$(RESET)"
@echo ""
./project5 < test-data/t08-local.in > test-data/project5.out
diff test-data/project5.out test-data/t08-local.out > test.diff
rm test.diff && rm project5.out
@echo "$(GREEN)Passed!$(RESET)"
-@diff test-data/project5.out test-data/t08-local.out > test.diff && echo "$(GREEN)Passed!$(RESET)"

# test the code against an expected output file
test-combo: project5
@echo ""
@echo "$(RED)--- Combo Test ---$(RESET)"
@echo ""
./project5 < test-data/t0502-combo.in > test-data/project5.out
diff test-data/project5.out test-data/t0502-combo.out > test.diff
rm test.diff && rm project5.out
@echo "$(GREEN)Passed!$(RESET)"
-@diff test-data/project5.out test-data/t0502-combo.out > test.diff && echo "$(GREEN)Passed!$(RESET)"
54 changes: 42 additions & 12 deletions province.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <string>
#include <stack>
#include <cfloat>
#include <array>

#include "province.h"

Expand Down Expand Up @@ -179,18 +180,10 @@ void Province::printShortestPath(std::ostream & output) const {
cout << endl;
}

/**
* < operator used to compare two roads
* @param road2 A road
* @return True if road1 is shorter in length than road 2
*/
bool Province::Road::operator < (Road road2) const {
return this->_length < road2._length;
}

/**
* Find minimum cost spanning tree of the province
*/
void Province::minSpan(std::ostream & output) const {
// if only one town
if (_numberOfTowns == 1) {
Expand Down Expand Up @@ -313,6 +306,10 @@ std::vector<int> Province::bfs(int start) const {
return results;
}

void ap(int dfsTree[]) {

}

/**
* Remove bridges and print the list of towns that remain connected
*/
Expand Down Expand Up @@ -360,6 +357,40 @@ void Province::removeBridges(ostream &output) const {
}
}

void Province::dfs(vector<int> & dfsTowns) const {
stack<int> toExplore;
int town = 0;
bool visited[_numberOfTowns];
memset(visited, false, sizeof visited);
while(true) {
cerr << "while" << endl;
visited[town] = true;
cerr << "town " << _towns[town]._name << " is " << visited[town] << endl;
// find an unvisited road and continue while loop
for (std::list<Road>::const_iterator it = _towns[town]._roads.begin(); it != _towns[town]._roads.end(); it++) {
cerr << _towns[town]._name << "'s " << _towns[it->_head]._name << " " << _towns[it->_tail]._name << " " << _towns[town]._roads.size() << endl;
if (!visited[it->_head]) {
cerr << "New visit" << endl;
toExplore.push(town);
dfsTowns.push_back(town);
town = it->_head;
break;
}
}
if (toExplore.empty()) {
cerr << "empty" << endl;
break;
} else {
cerr << "leaf" << endl;
town = toExplore.top();
toExplore.pop();
}
}
for(std::vector<int>::iterator it = std::begin(dfsTowns); it != std::end(dfsTowns); ++it) {
std::cout << *it << "\n";
}
}

void Province::APUtil(int u, bool visited[],
int disc[], int low[], int& time, int parent,
bool isAP[]) const {
Expand Down Expand Up @@ -402,6 +433,7 @@ void Province::APUtil(int u, bool visited[],

void Province::articulationPoints(std::ostream & output) const
{

int disc[_numberOfTowns];
memset(disc, 0, sizeof disc);
int low[_numberOfTowns];
Expand All @@ -410,6 +442,8 @@ void Province::articulationPoints(std::ostream & output) const
bool isAP[_numberOfTowns];
memset(isAP, false, sizeof isAP);
int time = 0, par = -1;
vector<int> towns;
dfs(towns);

// Adding this loop so that the
// code works even if we are given
Expand All @@ -433,8 +467,4 @@ void Province::articulationPoints(std::ostream & output) const
output << " (None)" << endl;
}
output << endl;

for (bool i : isAP) {
cerr << i << endl;
}
}
1 change: 1 addition & 0 deletions province.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class Province {

int smallest(double dist [], std::list <int> toVisit, int numTowns) const;

void dfs(std::vector<int> & dfsTowns) const;
/**
* Conduct a breadth-first traversal on the province, ignoring bridges
* @param start Index of town to start traversal at
Expand Down
5 changes: 5 additions & 0 deletions tes.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
g++ -std=c++11 -o project5 project5.cc province.cc

--- Local Test ---(B

./project5 < test-data/t08-local.in > test-data/project5.out
Loading

0 comments on commit 574c828

Please sign in to comment.