Click here to Skip to main content
15,900,108 members
Home / Discussions / Java
   

Java

 
GeneralRe: How to set java path in coding( this data is useful) Pin
002comp15-May-10 3:03
002comp15-May-10 3:03 
GeneralRe: How to set java path in coding( this data is useful) Pin
Richard MacCutchan15-May-10 4:27
mveRichard MacCutchan15-May-10 4:27 
GeneralRe: How to set java path in coding( this data is useful) Pin
002comp16-May-10 20:42
002comp16-May-10 20:42 
GeneralRe: How to set java path in coding( this data is useful) (Atlast Solved) Pin
002comp17-May-10 1:11
002comp17-May-10 1:11 
GeneralRe: How to set java path in coding( this data is useful) (Atlast Solved) Pin
Richard MacCutchan17-May-10 1:43
mveRichard MacCutchan17-May-10 1:43 
QuestionHelp Regarding webservices Pin
Y_Kaushik13-May-10 18:38
Y_Kaushik13-May-10 18:38 
AnswerRe: Help Regarding webservices Pin
David Skelly13-May-10 22:41
David Skelly13-May-10 22:41 
QuestionPython to Java Pin
georg11312-May-10 12:40
georg11312-May-10 12:40 
Hello,
i get quite short code of algorithm in python, but i need to translate it to Java. I didnt find any program to do that, so i will really appreciate to help translating it.

I learned python a little to know how algorithm work.

The biggest problem is because in python all is object and some things are made really very confuzing. At first i dont know which structure to take in java.

code is:
[CODE]
class FlowNetwork(object):
    def __init__(self):
        self.adj, self.flow, = {},{}

    def add_vertex(self, vertex):
        self.adj[vertex] = []
       
    def get_edges(self, v):
        return self.adj[v]

    def add_edge(self, u,v,w=0):
        self.adj[u].append((v,w))
        self.adj[v].append((u,0))
        self.flow[(u,v)] = self.flow[(v,u)] = 0

    def find_path(self, source, sink, path):
        if source == sink:
            return path
        for vertex, capacity in self.get_edges(source):
            residual = capacity - self.flow[(source,vertex)]
            edge = (source,vertex,residual)
            if residual > 0 and not edge in path:
                result = self.find_path(vertex, sink, path + [edge])
                if result != None:
                    return result

    def max_flow(self, source, sink):
        path = self.find_path(source, sink, [])
        while path != None:
            flow = min(r for u,v,r in path)
            for u,v,_ in path:
                self.flow[(u,v)] += flow
                self.flow[(v,u)] -= flow
                path = self.find_path(source, sink, [])
        return sum(self.flow[(source, vertex)] for vertex, capacity in self.get_edges(source))

g = FlowNetwork()
map(g.add_vertex, ['s','o','p','q','r','t'])
g.add_edge('s','o',3)
g.add_edge('s','p',3)
g.add_edge('o','p',2)
g.add_edge('o','q',3)
g.add_edge('p','r',2)
g.add_edge('r','t',3)
g.add_edge('q','r',4)
g.add_edge('q','t',2)
print g.max_flow('s','t')
[/CODE] 

result of this example is "5".


algorithm find max flow in graph(linked list or whatever) from source vertex "s" to destination "t".


Many thanx for any idea
AnswerRe: Python to Java Pin
Richard MacCutchan12-May-10 22:32
mveRichard MacCutchan12-May-10 22:32 
GeneralRe: Python to Java Pin
georg11313-May-10 7:38
georg11313-May-10 7:38 
AnswerRe: Python to Java Pin
427748013-May-10 23:38
427748013-May-10 23:38 
Questionwhat is date overlapping? Pin
kirancgi12-May-10 2:41
kirancgi12-May-10 2:41 
AnswerRe: what is date overlapping? Pin
Richard MacCutchan12-May-10 4:54
mveRichard MacCutchan12-May-10 4:54 
Questionjava.net.MalformedURLException when creating an URL object [Solved] Pin
Bob Stanneveld5-May-10 22:28
Bob Stanneveld5-May-10 22:28 
AnswerRe: java.net.MalformedURLException when creating an URL object Pin
TorstenH.6-May-10 0:48
TorstenH.6-May-10 0:48 
AnswerRe: java.net.MalformedURLException when creating an URL object Pin
Richard MacCutchan6-May-10 1:49
mveRichard MacCutchan6-May-10 1:49 
AnswerRe: java.net.MalformedURLException when creating an URL object Pin
David Skelly6-May-10 2:12
David Skelly6-May-10 2:12 
GeneralRe: java.net.MalformedURLException when creating an URL object Pin
Bob Stanneveld6-May-10 2:19
Bob Stanneveld6-May-10 2:19 
GeneralRe: java.net.MalformedURLException when creating an URL object Pin
Richard MacCutchan6-May-10 2:40
mveRichard MacCutchan6-May-10 2:40 
GeneralRe: java.net.MalformedURLException when creating an URL object Pin
David Skelly6-May-10 5:24
David Skelly6-May-10 5:24 
AnswerRe: java.net.MalformedURLException when creating an URL object [Solved] Pin
Bob Stanneveld6-May-10 5:33
Bob Stanneveld6-May-10 5:33 
QuestionJava Heap Space problem Pin
002comp3-May-10 22:39
002comp3-May-10 22:39 
AnswerRe: Java Heap Space problem Pin
Arrpita6-May-10 16:17
Arrpita6-May-10 16:17 
GeneralRe: Java Heap Space problem(solved) Pin
002comp7-May-10 2:16
002comp7-May-10 2:16 
GeneralRe: Java Heap Space problem(solved) Pin
Arrpita7-May-10 15:40
Arrpita7-May-10 15:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.