The Wayback Machine - https://web.archive.org/web/20201103190421/https://github.com/TheAlgorithms/Java/pull/453
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added implementation of the Max flow algorithm (Dinic) and Topological sorting #453

Open
wants to merge 3 commits into
base: master
from

Conversation

@PalAditya
Copy link
Contributor

@PalAditya PalAditya commented Jun 8, 2018

Thanks for merging my first PR. I would like to keep contributing, if that's okay? :)
Please tel me about any mistakes though.

@christianbender
Copy link
Collaborator

@christianbender christianbender commented Jul 3, 2018

@PalAditya

Thanks for merging my first PR. I would like to keep contributing, if that's okay? :)

of course 👍

Copy link
Collaborator

@christianbender christianbender left a comment

Good Work! I have some suggestions.

{
private int V,level[];
private ArrayList<Edge> adj[];
class Edge

This comment has been minimized.

@christianbender

christianbender Jul 21, 2018
Collaborator

In latest version of Java (java 8) you don't need inner classes. You can write this sperated in one single file like:

// one file
class A {

}

class B {

}

// ... 

g.addEdge(4, 3, 7 );
g.addEdge(4, 5, 4);
System.out.println( "Maximum flow is: "+g.DinicMaxflow(0, 5));
}

This comment has been minimized.

@christianbender

christianbender Jul 21, 2018
Collaborator

If I compile this I get:

Note: MaxFlowDinic.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

You must use type specifies <TYPE> by each collection.

* @param s=Source vertex
* @param t=Sink Vertex
*/
private boolean BFS(int s,int t)

This comment has been minimized.

@christianbender

christianbender Jul 21, 2018
Collaborator

Please use java naming conventions (camelCase)

*/
void addEdge(int u, int v, double C)
{
Edge a=new Edge(v, 0, C, adj[v].size());// Forward edge : 0 flow and C capacity

This comment has been minimized.

@christianbender

christianbender Jul 21, 2018
Collaborator

Please put in spaces between the operators like =

public static void main(String args[])
{
MaxFlowDinic obj=new MaxFlowDinic(0);//Dummy object to access the non-static methods
obj.go();

This comment has been minimized.

@christianbender

christianbender Jul 21, 2018
Collaborator

Put in the expecting output.

double DinicMaxflow(int s, int t)
{
// Corner case
if (s == t)

This comment has been minimized.

@christianbender

christianbender Jul 21, 2018
Collaborator

Use curly braces.

g.addEdge(4, 1);
g.addEdge(2, 3);
g.addEdge(3, 1);
g.topologicalSort();

This comment has been minimized.

@christianbender

christianbender Jul 21, 2018
Collaborator

Add comments for the expected output.

g.addEdge(3, 1);
g.topologicalSort();
}
}

This comment has been minimized.

@christianbender

christianbender Jul 21, 2018
Collaborator

Same warning as above.

Note: TopologicalSort.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

private void topologicalSortUtil(int v, boolean visited[], Stack stack)
{
visited[v] = true;// Marking the current node as visited.
Integer i;

This comment has been minimized.

@christianbender

christianbender Jul 21, 2018
Collaborator

Write instead int i = 0;

visited[i] = true;
recStack[i] = true;
List<Integer> children = adj[i];
for (Integer c: children)

This comment has been minimized.

@christianbender

christianbender Jul 21, 2018
Collaborator

Write int c

@varunu28
Copy link
Collaborator

@varunu28 varunu28 commented Aug 2, 2018

@PalAditya Can you please do the changes requested? Otherwise you can close this PR and open a fresh one with changes implemented later

@PalAditya
Copy link
Contributor Author

@PalAditya PalAditya commented Aug 3, 2018

PalAditya added 2 commits Aug 5, 2018
@PalAditya
Copy link
Contributor Author

@PalAditya PalAditya commented Aug 5, 2018

Made the requested changes

@barchiye
Copy link

@barchiye barchiye commented Aug 15, 2018

hello everyone ....hope all of u are fine ...i just want to get the source code of modified throttled algorithm for load balancing algorithm in cloud computing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.