Newsgroups: comp.ai.games
Path: cantaloupe.srv.cs.cmu.edu!rochester!udel!gatech!howland.reston.ans.net!Germany.EU.net!news.dfn.de!news.uni-augsburg.de!news
From: Pit <schaefer@malaga.math.uni-augsburg.de>
Subject: Re: A twist on Shortest path. any advice?
Message-ID: <DFoA77.CvE@Yuri.CC.Uni-Augsburg.DE>
Sender: news@Yuri.CC.Uni-Augsburg.DE (The News Administrator)
Nntp-Posting-Host: cadiz.math.uni-augsburg.de
Organization: Computer Center, University of Augsburg, Germany
References: <434i8f$ho2@bmerhc5e.bnr.ca> <34955.0309953704@localhost>
Date: Fri, 29 Sep 1995 15:11:29 GMT
Lines: 124

> >in order to get a comodity from one place (oh city) to another
> >the shortest path will tell you how to get it there in a weighted graph.
> >Ex:
> >
> >(-1)--1--(0)--5--(+1)      the best way to get comodity from the
> >    \     |     /          surplus (+1) to the demand (-1)
> >     5    2    1           is on the route including edges of
> >      \   |   /            weight 1,2,1 total 4.
> >       \  |  /
> >        \ | /
> >         (0)

I think it should work like this( from memory ):
( you can also read the shorter '==implementation for games==' 
 if you only want to sniff the spirit of the algorithm. )

let N be the number of nodes.
make an empty list of nodes to be processed("2bp").
set all current edges, distance=0 , etc., for all nodes.

data: 
a node has to contain this information( in some form :) 
      distance estimate( 'label' ). ( set to 0 )
      current(next)edge.            ( current->next= best node to start with )
      this points to a list of edges leading away from the node.  
      goods not transported yet( 'freight' ). ( 0 but for the two src and dst nodes )    
an edge has to know it's carrying capacity,
in both directions(!).  

0:sort the edges by distance to destination or(?) length( lowest first ).

1:Use the following 'push-and-relabel' algorithm:

assign N+1 as distance estimate to the 'source' node, zero to all
other nodes. put the src node into 2bp.

for the first node in 2bp do
   take next current node.
  if there is an eligible current edge left
  (!=NULL)&&( label <= this label )
    push the cargo left to the current node.
    the pushing operation has to adjust the capacity of the edge,
    and of the freight left to be transported. it also should
    reject the transport if the capacity of the edge is zero,
    and the pushed load is positive.

    add the current node to the front of the 2bp queue.
    relabel this node to(*) 1 + label of next node. 
  else{ backtrack}
    add one to the label of this node.
    remove this node from the top of the queue.
    the node that is now on top of the queue should be
    the node that pushed the load before.
    push the freight that is left back to that node.
    you also have to to something to the labels here,
    I think set it to 1+node pushing back.

  ends when freight to push=0 or label=N+1 ( something like this )

2:put my name into your people-to-employ-when-i-get-rich.list .
  A written proof that i practised mathematics in your enterprise 
  also'd be appreciated, as my university is eager on it.

Lets see if that does it.
Hope i interpret your example right.
you can also use more than one source and more than one destination
by linking all of them to a pool, like this:
// (label)--capacity--  +-freight

(0)--1--(0)--1--(0)--5--(0)--1--(7)
-1        \      |      /        +1
           \     |     /   
            \    2    /
             5   |   1 
              \  |  /    
                (0)
                          
The algorithm starts by pushing a load of one along the edge,
reducing the edges capacity to zero, and incresing the pushing 
capacity backwards to 2( =unpush one and push one ).
As the bottom node is marked as having fewest distance( or selected 
by heuristics ), push a load of 1 to it, set its label to 1(=0+1) and
get back to queue, where the bottom node is top now.
The bottom node starts pushing to the node above it,
setting the edges capacity to (4 forewards,6 backwards),
and sets it's label to 2.
The top node( top of queue as well ),now does the same,
and the cargo gets through to the destination pool,
where the algorithm ends because all nodes in the 2bp list 
have zero freight. Ah yes, and all nodes in the 2bp list will
also set the label to 1+ the label before.
In the form above, the pointers will show any single route when the
algorithm ends, but more routes have to be recorded somewhere,
along with the pushes along edges.

BTW: the problem is NP-complex.

=================implementation for games=======================
A sloppy version of this can be implemented in real time by
pushing ,like simultaneously, between nodes, and by pushing once 
per turn. every node( city ) then needs a distance( label ) list 
to all other nodes, which is updated along the above guidelines:
( Set it to distance+distance(previous node) when pushing forward,
  and to distance+distance(previous node) whenever a 'parcel
  arrived succesfully' message is sent back the track the parcel went.)

peter schaefer
http://wwwhoppe.math.uni-augsburg.de/schaefer/
D 86153 Augsburg, Lindenstr. 4

" no motto is better than this "





  

  





