Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Feb 4, 2025
1 parent 0b615ae commit f53de71
Show file tree
Hide file tree
Showing 20 changed files with 758 additions and 758 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pdd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ jobs:
pdd:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: g4s8/pdd-action@master
4 changes: 2 additions & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- run: npm install -g eolang
- run: make
- run: make run
- run: make run
2 changes: 1 addition & 1 deletion .github/workflows/xcop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ jobs:
xcop:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: g4s8/xcop-action@master
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ run:
echo "Test ($$FILE) is running"; \
$(J); printjava $$(java -cp $(TARGPATH)/java prim/PrimMST $$var); \
$(C); printcpp $$($(TARGPATH)/cpp/prim $$var); \

@cd ../../src/eo
$(E); printeo $$(eoc --alone dataize app $$var)
@cd ../../tests/edges/
echo "\n";
done

@cd ../list
@echo "Now we are going to run Dijkstra's algorithm \n";
@for FILE in *; do \
Expand All @@ -90,4 +90,4 @@ clean:
rm -f -r targets/
rm -f tests/edges/star3.graph
rm -f tests/list/dijkstra2.graph
rm -f -r src/eo/.eoc
rm -f -r src/eo/.eoc
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ $ make run

By the way, the graphs are generated randomly by the [utility](https://github.com/potatmen/eo-graphs/blob/master/src/java/generator/GraphGenerator.java) written in Java.

## Algorithms
## Algorithms

The following graph algorithms are implemented:

Expand Down
2 changes: 1 addition & 1 deletion src/cpp/dijkstra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ int main(int argc, char *argv[])
}

return 0;
}
}
28 changes: 14 additions & 14 deletions src/cpp/fordfalkersonalg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,31 @@ int capacity[MAX_E], onEnd[MAX_E], nextEdge[MAX_E], edgeCount;
int firstEdge[MAX_V], visited[MAX_V];

void addEdge(int u, int v, int cap) {
onEnd[edgeCount] = v;
nextEdge[edgeCount] = firstEdge[u];
firstEdge[u] = edgeCount;
capacity[edgeCount++] = cap;
onEnd[edgeCount] = u;
nextEdge[edgeCount] = firstEdge[v];
firstEdge[v] = edgeCount;
capacity[edgeCount++] = 0;
onEnd[edgeCount] = v;
nextEdge[edgeCount] = firstEdge[u];
firstEdge[u] = edgeCount;
capacity[edgeCount++] = cap;
onEnd[edgeCount] = u;
nextEdge[edgeCount] = firstEdge[v];
firstEdge[v] = edgeCount;
capacity[edgeCount++] = 0;
}

int findFlow(int u, int flow) {
if (u == destinationVertex) return flow;
if (u == destinationVertex) return flow;
visited[u] = true;
for (int edge = firstEdge[u]; edge != -1; edge = nextEdge[edge]) {
int to = onEnd[edge];
if (!visited[to] && capacity[edge] > 0) {
int minResult = findFlow(to, min(flow, capacity[edge]));
if (minResult > 0) {
capacity[edge] -= minResult;
capacity[edge ^ 1] += minResult;
int minResult = findFlow(to, min(flow, capacity[edge]));
if (minResult > 0) {
capacity[edge] -= minResult;
capacity[edge ^ 1] += minResult;
return minResult;
}
}
}
return 0;
return 0;
}

int main(int argc, char *argv[]) {
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/prim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@ int main (int argc, char *argv[]) {
}

return 0;
}
}
2 changes: 1 addition & 1 deletion src/java/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ run:
@mkdir $(TARGPATH)/java
for FILE in **/*.java; do \
javac -d $(TARGPATH)/java $$FILE; \
done
done
34 changes: 17 additions & 17 deletions src/java/fordfalkersonalg/FordFalkerson.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import java.lang.*;
import java.util.Arrays;
import java.util.LinkedList;

class FordFalkerson {

/* Returns true if there is a path from source 's' to
sink 't' in residual graph. Also fills parent[] to
store the path */
Expand All @@ -16,19 +16,19 @@ boolean bfs(int rGraph[][], int s, int t, int parent[])
boolean visited[] = new boolean[V];
for (int i = 0; i < V; ++i)
visited[i] = false;

// Create a queue, enqueue source vertex and mark
// source vertex as visited
LinkedList<Integer> queue
= new LinkedList<Integer>();
queue.add(s);
visited[s] = true;
parent[s] = -1;

// Standard BFS Loop
while (queue.size() != 0) {
int u = queue.poll();

for (int v = 0; v < V; v++) {
if (visited[v] == false
&& rGraph[u][v] > 0) {
Expand All @@ -46,39 +46,39 @@ boolean bfs(int rGraph[][], int s, int t, int parent[])
}
}
}

// We didn't reach sink in BFS starting from source,
// so return false
return false;
}

// Returns tne maximum flow from s to t in the given
// graph
int fordFulkerson(int graph[][], int s, int t)
{
int u, v;

final int V = graph.length;

// Create a residual graph and fill the residual
// graph with given capacities in the original graph
// as residual capacities in residual graph

// Residual graph where rGraph[i][j] indicates
// residual capacity of edge from i to j (if there
// is an edge. If rGraph[i][j] is 0, then there is
// not)
int rGraph[][] = new int[V][V];

for (u = 0; u < V; u++)
for (v = 0; v < V; v++)
rGraph[u][v] = graph[u][v];

// This array is filled by BFS and to store path
int parent[] = new int[V];

int max_flow = 0; // There is no flow initially

// Augment the flow while tere is path from source
// to sink
while (bfs(rGraph, s, t, parent)) {
Expand All @@ -91,23 +91,23 @@ int fordFulkerson(int graph[][], int s, int t)
path_flow
= Math.min(path_flow, rGraph[u][v]);
}

// update residual capacities of the edges and
// reverse edges along the path
for (v = t; v != s; v = parent[v]) {
u = parent[v];
rGraph[u][v] -= path_flow;
rGraph[v][u] += path_flow;
}

// Add path flow to overall flow
max_flow += path_flow;
}

// Return the overall flow
return max_flow;
}

// Driver program to test above functions
public static void main(String[] args)
throws java.lang.Exception
Expand Down
2 changes: 1 addition & 1 deletion src/java/kruskal/kruskal.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,4 @@ public int compareTo(Edge compareEdge)
{
return this.weight - compareEdge.weight;
}
};
};
2 changes: 1 addition & 1 deletion src/java/prim/PrimMST.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@ public static void main(String[] args) {
}

}
}
}
Loading

0 comments on commit f53de71

Please sign in to comment.