diff --git a/E512W3DUtils.hpp b/E512W3DUtils.hpp index 2a3ae60..4bd47a5 100644 --- a/E512W3DUtils.hpp +++ b/E512W3DUtils.hpp @@ -357,22 +357,22 @@ class E512PriorityQueueMax { } }; -struct GraphEdge { +struct E512Edge { public: int a, b, cost; - GraphEdge () { + E512Edge () { this->a = 0; this->b = 0; this->cost = 1000000; } - GraphEdge (int a, int b, int cost) { + E512Edge (int a, int b, int cost) { this->a = a; this->b = b; this->cost = cost; } - bool operator == (const GraphEdge& t) const { return this->a == t.a && this->b == t.b; } + bool operator == (const E512Edge& t) const { return this->a == t.a && this->b == t.b; } }; -class GraphDijkstra { +class E512GraphDijkstra { private: class Node { public: @@ -397,9 +397,9 @@ class GraphDijkstra { E512Array rpath; int pathcost; - GraphDijkstra () {} + E512GraphDijkstra () {} - GraphDijkstra (int n, E512Array edges, bool undir = false) { + E512GraphDijkstra (int n, E512Array& edges, bool undir = false) { this->pathcost = 0; this->path.clear(); this->n = n; @@ -417,7 +417,7 @@ class GraphDijkstra { } } - GraphDijkstra (E512Array edges, bool undir = false) { + E512GraphDijkstra (E512Array& edges, bool undir = false) { this->pathcost = 0; this->path.clear(); int n = 0; @@ -436,6 +436,20 @@ class GraphDijkstra { } } + void costUpdate (E512Array& edges, bool undir = false) { + for (auto&& i : this->edgecost) { i.clear(); } + if (undir) {// undirected + for (auto&& i : edges) { + this->edgecost[i.a].emplace_back(i.b, i.cost); + this->edgecost[i.b].emplace_back(i.a, i.cost); + } + } else {// directed + for (auto&& i : edges) { + this->edgecost[i.a].emplace_back(i.b, i.cost); + } + } + } + void calcPath (int start_i, int end_i) { this->path.clear(); this->rpath.clear(); diff --git a/examples/example1/E512W3DUtils.hpp b/examples/example1/E512W3DUtils.hpp index 2a3ae60..4bd47a5 100644 --- a/examples/example1/E512W3DUtils.hpp +++ b/examples/example1/E512W3DUtils.hpp @@ -357,22 +357,22 @@ class E512PriorityQueueMax { } }; -struct GraphEdge { +struct E512Edge { public: int a, b, cost; - GraphEdge () { + E512Edge () { this->a = 0; this->b = 0; this->cost = 1000000; } - GraphEdge (int a, int b, int cost) { + E512Edge (int a, int b, int cost) { this->a = a; this->b = b; this->cost = cost; } - bool operator == (const GraphEdge& t) const { return this->a == t.a && this->b == t.b; } + bool operator == (const E512Edge& t) const { return this->a == t.a && this->b == t.b; } }; -class GraphDijkstra { +class E512GraphDijkstra { private: class Node { public: @@ -397,9 +397,9 @@ class GraphDijkstra { E512Array rpath; int pathcost; - GraphDijkstra () {} + E512GraphDijkstra () {} - GraphDijkstra (int n, E512Array edges, bool undir = false) { + E512GraphDijkstra (int n, E512Array& edges, bool undir = false) { this->pathcost = 0; this->path.clear(); this->n = n; @@ -417,7 +417,7 @@ class GraphDijkstra { } } - GraphDijkstra (E512Array edges, bool undir = false) { + E512GraphDijkstra (E512Array& edges, bool undir = false) { this->pathcost = 0; this->path.clear(); int n = 0; @@ -436,6 +436,20 @@ class GraphDijkstra { } } + void costUpdate (E512Array& edges, bool undir = false) { + for (auto&& i : this->edgecost) { i.clear(); } + if (undir) {// undirected + for (auto&& i : edges) { + this->edgecost[i.a].emplace_back(i.b, i.cost); + this->edgecost[i.b].emplace_back(i.a, i.cost); + } + } else {// directed + for (auto&& i : edges) { + this->edgecost[i.a].emplace_back(i.b, i.cost); + } + } + } + void calcPath (int start_i, int end_i) { this->path.clear(); this->rpath.clear(); diff --git a/examples/example2/E512W3DUtils.hpp b/examples/example2/E512W3DUtils.hpp index 2a3ae60..4bd47a5 100644 --- a/examples/example2/E512W3DUtils.hpp +++ b/examples/example2/E512W3DUtils.hpp @@ -357,22 +357,22 @@ class E512PriorityQueueMax { } }; -struct GraphEdge { +struct E512Edge { public: int a, b, cost; - GraphEdge () { + E512Edge () { this->a = 0; this->b = 0; this->cost = 1000000; } - GraphEdge (int a, int b, int cost) { + E512Edge (int a, int b, int cost) { this->a = a; this->b = b; this->cost = cost; } - bool operator == (const GraphEdge& t) const { return this->a == t.a && this->b == t.b; } + bool operator == (const E512Edge& t) const { return this->a == t.a && this->b == t.b; } }; -class GraphDijkstra { +class E512GraphDijkstra { private: class Node { public: @@ -397,9 +397,9 @@ class GraphDijkstra { E512Array rpath; int pathcost; - GraphDijkstra () {} + E512GraphDijkstra () {} - GraphDijkstra (int n, E512Array edges, bool undir = false) { + E512GraphDijkstra (int n, E512Array& edges, bool undir = false) { this->pathcost = 0; this->path.clear(); this->n = n; @@ -417,7 +417,7 @@ class GraphDijkstra { } } - GraphDijkstra (E512Array edges, bool undir = false) { + E512GraphDijkstra (E512Array& edges, bool undir = false) { this->pathcost = 0; this->path.clear(); int n = 0; @@ -436,6 +436,20 @@ class GraphDijkstra { } } + void costUpdate (E512Array& edges, bool undir = false) { + for (auto&& i : this->edgecost) { i.clear(); } + if (undir) {// undirected + for (auto&& i : edges) { + this->edgecost[i.a].emplace_back(i.b, i.cost); + this->edgecost[i.b].emplace_back(i.a, i.cost); + } + } else {// directed + for (auto&& i : edges) { + this->edgecost[i.a].emplace_back(i.b, i.cost); + } + } + } + void calcPath (int start_i, int end_i) { this->path.clear(); this->rpath.clear(); diff --git a/examples/example3/E512W3DUtils.hpp b/examples/example3/E512W3DUtils.hpp index 2a3ae60..4bd47a5 100644 --- a/examples/example3/E512W3DUtils.hpp +++ b/examples/example3/E512W3DUtils.hpp @@ -357,22 +357,22 @@ class E512PriorityQueueMax { } }; -struct GraphEdge { +struct E512Edge { public: int a, b, cost; - GraphEdge () { + E512Edge () { this->a = 0; this->b = 0; this->cost = 1000000; } - GraphEdge (int a, int b, int cost) { + E512Edge (int a, int b, int cost) { this->a = a; this->b = b; this->cost = cost; } - bool operator == (const GraphEdge& t) const { return this->a == t.a && this->b == t.b; } + bool operator == (const E512Edge& t) const { return this->a == t.a && this->b == t.b; } }; -class GraphDijkstra { +class E512GraphDijkstra { private: class Node { public: @@ -397,9 +397,9 @@ class GraphDijkstra { E512Array rpath; int pathcost; - GraphDijkstra () {} + E512GraphDijkstra () {} - GraphDijkstra (int n, E512Array edges, bool undir = false) { + E512GraphDijkstra (int n, E512Array& edges, bool undir = false) { this->pathcost = 0; this->path.clear(); this->n = n; @@ -417,7 +417,7 @@ class GraphDijkstra { } } - GraphDijkstra (E512Array edges, bool undir = false) { + E512GraphDijkstra (E512Array& edges, bool undir = false) { this->pathcost = 0; this->path.clear(); int n = 0; @@ -436,6 +436,20 @@ class GraphDijkstra { } } + void costUpdate (E512Array& edges, bool undir = false) { + for (auto&& i : this->edgecost) { i.clear(); } + if (undir) {// undirected + for (auto&& i : edges) { + this->edgecost[i.a].emplace_back(i.b, i.cost); + this->edgecost[i.b].emplace_back(i.a, i.cost); + } + } else {// directed + for (auto&& i : edges) { + this->edgecost[i.a].emplace_back(i.b, i.cost); + } + } + } + void calcPath (int start_i, int end_i) { this->path.clear(); this->rpath.clear(); diff --git a/examples/example4/E512W3DUtils.hpp b/examples/example4/E512W3DUtils.hpp index 2a3ae60..4bd47a5 100644 --- a/examples/example4/E512W3DUtils.hpp +++ b/examples/example4/E512W3DUtils.hpp @@ -357,22 +357,22 @@ class E512PriorityQueueMax { } }; -struct GraphEdge { +struct E512Edge { public: int a, b, cost; - GraphEdge () { + E512Edge () { this->a = 0; this->b = 0; this->cost = 1000000; } - GraphEdge (int a, int b, int cost) { + E512Edge (int a, int b, int cost) { this->a = a; this->b = b; this->cost = cost; } - bool operator == (const GraphEdge& t) const { return this->a == t.a && this->b == t.b; } + bool operator == (const E512Edge& t) const { return this->a == t.a && this->b == t.b; } }; -class GraphDijkstra { +class E512GraphDijkstra { private: class Node { public: @@ -397,9 +397,9 @@ class GraphDijkstra { E512Array rpath; int pathcost; - GraphDijkstra () {} + E512GraphDijkstra () {} - GraphDijkstra (int n, E512Array edges, bool undir = false) { + E512GraphDijkstra (int n, E512Array& edges, bool undir = false) { this->pathcost = 0; this->path.clear(); this->n = n; @@ -417,7 +417,7 @@ class GraphDijkstra { } } - GraphDijkstra (E512Array edges, bool undir = false) { + E512GraphDijkstra (E512Array& edges, bool undir = false) { this->pathcost = 0; this->path.clear(); int n = 0; @@ -436,6 +436,20 @@ class GraphDijkstra { } } + void costUpdate (E512Array& edges, bool undir = false) { + for (auto&& i : this->edgecost) { i.clear(); } + if (undir) {// undirected + for (auto&& i : edges) { + this->edgecost[i.a].emplace_back(i.b, i.cost); + this->edgecost[i.b].emplace_back(i.a, i.cost); + } + } else {// directed + for (auto&& i : edges) { + this->edgecost[i.a].emplace_back(i.b, i.cost); + } + } + } + void calcPath (int start_i, int end_i) { this->path.clear(); this->rpath.clear(); diff --git a/multicore/examplem/E512W3DUtils.hpp b/multicore/examplem/E512W3DUtils.hpp index 2a3ae60..4bd47a5 100644 --- a/multicore/examplem/E512W3DUtils.hpp +++ b/multicore/examplem/E512W3DUtils.hpp @@ -357,22 +357,22 @@ class E512PriorityQueueMax { } }; -struct GraphEdge { +struct E512Edge { public: int a, b, cost; - GraphEdge () { + E512Edge () { this->a = 0; this->b = 0; this->cost = 1000000; } - GraphEdge (int a, int b, int cost) { + E512Edge (int a, int b, int cost) { this->a = a; this->b = b; this->cost = cost; } - bool operator == (const GraphEdge& t) const { return this->a == t.a && this->b == t.b; } + bool operator == (const E512Edge& t) const { return this->a == t.a && this->b == t.b; } }; -class GraphDijkstra { +class E512GraphDijkstra { private: class Node { public: @@ -397,9 +397,9 @@ class GraphDijkstra { E512Array rpath; int pathcost; - GraphDijkstra () {} + E512GraphDijkstra () {} - GraphDijkstra (int n, E512Array edges, bool undir = false) { + E512GraphDijkstra (int n, E512Array& edges, bool undir = false) { this->pathcost = 0; this->path.clear(); this->n = n; @@ -417,7 +417,7 @@ class GraphDijkstra { } } - GraphDijkstra (E512Array edges, bool undir = false) { + E512GraphDijkstra (E512Array& edges, bool undir = false) { this->pathcost = 0; this->path.clear(); int n = 0; @@ -436,6 +436,20 @@ class GraphDijkstra { } } + void costUpdate (E512Array& edges, bool undir = false) { + for (auto&& i : this->edgecost) { i.clear(); } + if (undir) {// undirected + for (auto&& i : edges) { + this->edgecost[i.a].emplace_back(i.b, i.cost); + this->edgecost[i.b].emplace_back(i.a, i.cost); + } + } else {// directed + for (auto&& i : edges) { + this->edgecost[i.a].emplace_back(i.b, i.cost); + } + } + } + void calcPath (int start_i, int end_i) { this->path.clear(); this->rpath.clear(); diff --git a/tilemap/exampletm/E512W3DUtils.hpp b/tilemap/exampletm/E512W3DUtils.hpp index 2a3ae60..4bd47a5 100644 --- a/tilemap/exampletm/E512W3DUtils.hpp +++ b/tilemap/exampletm/E512W3DUtils.hpp @@ -357,22 +357,22 @@ class E512PriorityQueueMax { } }; -struct GraphEdge { +struct E512Edge { public: int a, b, cost; - GraphEdge () { + E512Edge () { this->a = 0; this->b = 0; this->cost = 1000000; } - GraphEdge (int a, int b, int cost) { + E512Edge (int a, int b, int cost) { this->a = a; this->b = b; this->cost = cost; } - bool operator == (const GraphEdge& t) const { return this->a == t.a && this->b == t.b; } + bool operator == (const E512Edge& t) const { return this->a == t.a && this->b == t.b; } }; -class GraphDijkstra { +class E512GraphDijkstra { private: class Node { public: @@ -397,9 +397,9 @@ class GraphDijkstra { E512Array rpath; int pathcost; - GraphDijkstra () {} + E512GraphDijkstra () {} - GraphDijkstra (int n, E512Array edges, bool undir = false) { + E512GraphDijkstra (int n, E512Array& edges, bool undir = false) { this->pathcost = 0; this->path.clear(); this->n = n; @@ -417,7 +417,7 @@ class GraphDijkstra { } } - GraphDijkstra (E512Array edges, bool undir = false) { + E512GraphDijkstra (E512Array& edges, bool undir = false) { this->pathcost = 0; this->path.clear(); int n = 0; @@ -436,6 +436,20 @@ class GraphDijkstra { } } + void costUpdate (E512Array& edges, bool undir = false) { + for (auto&& i : this->edgecost) { i.clear(); } + if (undir) {// undirected + for (auto&& i : edges) { + this->edgecost[i.a].emplace_back(i.b, i.cost); + this->edgecost[i.b].emplace_back(i.a, i.cost); + } + } else {// directed + for (auto&& i : edges) { + this->edgecost[i.a].emplace_back(i.b, i.cost); + } + } + } + void calcPath (int start_i, int end_i) { this->path.clear(); this->rpath.clear();