Floyd warshall
  Home FAQ Contact Sign in
comp.lang.prolog only
 
Advanced search
POPULAR GROUPS

more...

comp.lang.prolog Profile…
 Up
Re: Floyd warshall         


Author: bart demoen
Date: Sep 1, 2007 03:40

On Sat, 01 Sep 2007 11:04:07 +0000, andrea wrote:
> Ok thanks, is it indented properly now?

min_dist(K, Cities, [C2 | T2]) :-
Cities=[C1|T1], K > 0, %% ***
J is K-1,
sh_path(C1,C2,Diretto,InfraD),
sh_path(C1,J,Before,InfraB),
sh_path(J,C2,After,InfraA),
S is Before+After,
(min(Diretto,S,Diretto) ->
write_min_dist(C1,C2,Diretto,InfraD),
min_dist(K,Cities,T2)
;
append(InfraB,InfraD,Total),
write_min_dist(C1,C2,Total,S),
min_dist(K,Cities,T2)
).
Show full article (1.05Kb)
no comments
Re: Floyd warshall         


Author: andrea
Date: Sep 1, 2007 10:31

On 1 Set, 12:40, bart demoen wrote:
> On Sat, 01 Sep 2007 11:04:07 +0000, andrea wrote:
>> Ok thanks, is it indented properly now?
>
> min_dist(K, Cities, [C2 | T2]) :-
> Cities=[C1|T1], K > 0, %% ***
> J is K-1,
> sh_path(C1,C2,Diretto,InfraD),
> sh_path(C1,J,Before,InfraB),
> sh_path(J,C2,After,InfraA),
> S is Before+After,
> (min(Diretto,S,Diretto) ->
> write_min_dist(C1,C2,Diretto,InfraD),
> min_dist(K,Cities,T2)
> ;
> append(InfraB,InfraD,Total),
> write_min_dist(C1,C2,Total,S),
> min_dist(K,Cities,T2)
> ).
> ...
Show full article (1.46Kb)
no comments
Re: Floyd warshall         


Author: andrea
Date: Sep 2, 2007 03:14

Last thing (I hope), I can't really find the (maybe logical) bug here.
I have a list of cities, say
[0,2,1,3]

I need to find distance from 0-2, 2-1, 1-3 and merge them (summing
distances and appending list of nodes I touch), giving the partial
result if there are no paths.

Now I think the base casa should be, sh_path/4 is in a file I consult
before, and is for example
sh_path(12,6,6,[3, 6]). in order (src,dst,distance,infraNodes).

Now I think the base case is when I find the last two cities, in this
example [1,3].

this is the code:

shortest_path([],0,[]). %%%% FIXME non funziona se percorso pi
no comments
Re: Floyd warshall         


Author: andrea
Date: Sep 2, 2007 04:22

I solved
shortest_path(L,D,Tappe) :-
length(L,Len),
(Len == 2 ->
L = [H,H1], sh_path(H,H1,D,Tappe);
L = [H,H1 | T], sh_path(H,H1,D1,Tappe1), shortest_path([H1 |
T],D2,Tappe2),
D is D1 + D2, append(Tappe1,Tappe2,Tappe)
).

The problem was that
[1,2] unifies with [H | [H1 | T1]], I was stupidly think it
wouldn't...
no comments
Re: Floyd warshall         


Author: andrea
Date: Sep 4, 2007 14:52

Ok now everything works and it's pretty fast (I didn't think so much),
there's just one last thing...
I manage the no link with a high integer (say 1000), that makes me
life easier with comparison, but it's not very wise.

In current_prolog_flag there may be the greatest integer but in my
version there is no bound, so how could I change this little thing??
Thanks a lot, this is the whole little program anyway

If you see something really wrong don't hesitate to write it...

#!/usr/bin/env swipl -q -g main -s

/* Schema di funzionamento generale :
Parsing dell'input =>
scrittura di distanze e citta su file temporaneo =>
consultazione =>
esecuzione di floyd Warshall e consultazione delle minime distanze =>
calcolo progressivo del percorso ottimale =>
scrittura su output del risultato ottenuto
*/
Show full article (3.92Kb)
no comments
Re: Floyd warshall         


Author: Nick Wedd
Date: Oct 20, 2007 08:37

In message <1188667905.145771.148130@19g2000hsx.googlegroups.com>,
andrea gmail.com> writes
>Thanks for the hints, but I like to have shorter files, one goal per
>line is too much for me, I just divide goals for their meanings...
>Anyway the whole program is almost working, it works with a small
>input but not for a larger one, still working..

Keep your files as short as you like; but when you post here, you are
more likely to get help if you reformat your predicates tidily, with one
goal per line.

Nick
--
Nick Wedd nick@maproom.co.uk
no comments
1 2 3