I am trying to calculate a transitive closure of a graph. Let`s consider this graph as an example (the picture depicts the graph, its adjacency and connectivity matrix):
Using Warshall's algorithm, which i found on this page, I generate this…
I have a bi-directional graph containing multiple clusters and non-trivial cycles, i.e. the graph contains cycles involving 3 or more nodes. The graph is represented as an edge table and the list of nodes is the set of unique nodes listed in the…
I have created the following function:
update_list3 = function(identity_dict){
suppressMessages(suppressWarnings({
library(ggm)
#adjacency matrix
g = matrix(unlist(lapply(identity_dict, FUN = function(x){
b =…
I am new in Prolog. I am trying to develop a Program which goal is, given the X,Y coordinate of a trophy (specified in the fact trofeo(4,3)), and the coordinates of some obstacles (specified in the fact ostacolo(,)), the Program has to find the…
I have a complete weighted directed graph G=(V,A,W) and I want to reduce the density of the graph by deleting arcs as follows: given i,j,k \in V if w(i,j)+w(j,k) <= w(i,k), then we delete arc (i,k).
The code is given below, where ad is initially the…
I'm trying to aggregate the below given table 1 to table 2 with Excel power queries.
The goal is to merge continuous time intervals of the same group into a single row. For direct overlappings like event 5 and 6 this was quite easy. But this…
I am new to logic programming. I am trying to write a program which can find all nodes which can reach to an specific node.
Here is my code:
link(0, 1).
link(3, 4).
link(1, 2).
link(2, 0).
link(2, 1).
link(3, 2).
link(4, 3).
So show above…
I want to create a TransitiveClosure() function in python that can input a dictionary and output a new dictionary of the transitive closure.
for example R = {1: [3], 2: [4], 3: [], 4: [1]} will output R R = {1 : [3], 2 : [1, 3, 4], 3 : [], 4 : [1,…
This is a very basic query, but I'm new to prolog and have trouble finding why this query does not terminate:
% fact
progeny(dexter, mark).
progeny(mark, bill).
progeny(bill, lisa).
% rule
progeny(X, Y) :- progeny(X, Z), progeny(Z, Y).
The…
I am trying to solve an exercise in MiniZinc in which a partial ordering relation is given by a 2-D array:
enum NODE = { A, B, C, D, E };
int : SOURCE = 1;
int : TARGET = 2;
array[int,1..2] of NODE: edge =
[| A, B % edge 1, source & edge…
I am trying to create a rule that recursively calls itself, and finds all possible paths to traverse a directed graph. I am using a findall() to do so. The functions is traverse(Start,End).
I have:
traverse(Start,End,[li]) :-
node(Start,End),
…
I am struggling to identify a way to convert a list to string. This list is the output from a findall predicate.
see below my code.
edge(a,b).
edge(a,c).
edge(b,c).
edge(c,d).
edge(c,e).
edge(d,e).
edge(f,g).
edge(g,h).
route(X, Z, []) :- …
I'm stuck with this recursion which doesn't work as I expect.
Where is my mistake?
#!/usr/bin/prolog
% Facts
mother( jeanne , michel ). % great-grandmother, grandfather
mother( genevieve, aubin ). % grandmother, father
mother( irene ,…
In reading a book on prolog I have come across trouble with this problem.
% Write a predicate travel_to/2 which determines whether it is possible to
% travel from one place to another by chaining together car, train, and
% plane journeys. For…