<p>Hmmm ... <a href="https://en.wikipedia.org/wiki/Betweenness_centrality" rel="nofollow noreferrer">Betweenness Centrality</a>. Complexity according to <a href="https://arxiv.org/abs/1311.2147" rel="nofollow noreferrer">Betweenness Centrality -- Incremental and Faster</a> is <em>O(mn + n^2 log n) time, where n = |V| and m = |E|</em> for the common algorithm, but can be improved with incremental edge updates. Interesting. </p>

<p>But your question is not about Betweenness Centrality but about the Cartesian Product?</p>

<p>To get the cartesian product of cities, you have to create a goal that chains two <code>member/2</code> calls, and then collect all solutions thereof with <code>bagof/3</code>: </p>

<pre><code>cities_1([berlin,tokyo,kigali,moscow]).
cities_2([beijing,new_delhi,cairo,lisboa]).

cartesian_product(CityPairs) :-
   cities_1(L1), 
   cities_2(L2), 
   bagof([C1,C2],(member(C1,L1),member(C2,L2)),CityPairs).
</code></pre>
How can I determine centrality in a node graph in Prolog?
<p>First of all this is not homework, just trying to learn Prolog on my own :)</p>

<p>I've been reading about graph theory and I thought it would be cool to implement betweeness centrality in my pet project. I have a list of cities and want to determine which one is more common in all shortest paths possible but I'm not sure how to get all two city combinations.</p>

<p>I already have a rule that gets the shortest path between two cities.</p>