1

Well, i got an undirected graph which looks like this.

graph

Each block represents an antenna (in a wireless phone network) and the black line splits the thing into different regions.
We have some facts like:

 region(r1, 2110, [1,2]).
 region(r2, 2210, [4,5,8]).
 region(r3, 2310, [3,6]).
 region(r4, 2410, [7,10,11,15]).
 region(r5, 2510, [9,12]).
 region(r6, 2610, [13,14]).

 telephone(2310-6-64221, name(andriopoulos, nikos)).
 telephone(2510-12-24234, name(papantoniou, kiki)). 

The first parameter is the name of the region, the second is a specific number that will be given to every person in their area (the first 4 numbers at each telephone of the current region) and the third is a list with all the areas that belong to the current region (the next number at the telephone, between the dashes).

My exercise says that every call to the same region is free, if it needs to pass one region is 1, if it is two regions away is two, etc.


I'm assigned to create the can_call/4 function that finds the route and the cost of a specific call between two people.
e.g.

?- can_call(papantoniou, andriopoulos, Route, Cost).
Route = [....]
Cost = ...

I have created a connect/2 function that tells me if 2 blocks are connected but i can't really think anything about the cost.
Any advice?

Guy Coder
  • 24,501
  • 8
  • 71
  • 136
Alator
  • 497
  • 6
  • 23
  • Post what you have written so far; how you determine if two regions are connection is closely related to how much a call between them will cost. – Scott Hunter May 27 '17 at 16:39
  • can_call(A,B,Route,Cost) :- telephone(F1-A1-D1,name(A,_)), telephone(F2-A2-D2,name(B,_)), path_loopcheck(A1,A2,Route). – Alator May 27 '17 at 16:47
  • the path_loopcheck is given method that finds the route between two blocks avoiding the infinite loops. – Alator May 27 '17 at 16:48

1 Answers1

1

when you have computed a route, a simple (and inefficient !) way to compute the number of regions change:

num_regions_change(Route, N) :-
  findall(t, (append(_, [X,Y|_], Route),
    region(P,_,Ps), memberchk(X,Ps),
    region(Q,_,Qs), memberchk(Y,Qs),
    P \= Q), Ns),
  length(Ns, N).

The append call will 'return' on backtracking - forced by findall - each pair of locations found in Route.

CapelliC
  • 59,646
  • 5
  • 47
  • 90