For now the emphasis is on plotting via igraph, qgraph and ggnet2, R libraries via Real.
A weighted graphs is represented as a list of From-To:W edges or Node entries for orphans.
See wgraph_plot/2.
pack(mtx).
When Graph is given, OutF is taken to be a file to store Graph in.
When Opts are given they can change the default column names of OutF.
Opts
?- wgraph( 'wgraph_ex.csv', [a-b:1,a-c:2,b-c:3] ). ?- wgraph( 'wgraph_ex.csv', G ), write( graph(G) ), nl. ?- wgraph( File, [a-b:1,a-c:2,b-c:3], [stem(wgraph_ex)] ). ?- wgraph( File, [a-b:1,a-c:2,b-c:3], [stem(wgraph_ex1)] ).
Requires library(mtx) iff you need to save/restore from csv.
Layout (see below) should be an mtx/1 matrix with at least two columns: x, y defining the positions of the nodes. In addition if columns: labels and colours are present but not given in Opts they will be used.
Graph can be an mtx/1 matrix with at least 2 columns: from and to.
In addition column weight is also processed. When missing and no weights option
is given, all weights are set to 1.
Opts
x11() call).
when Plotter is ggnet2 then Frm can x11 or any file extension recognised by
your installation of ggsave().layout_call(LayG) is not presentprop(Min,Mult)- size being proportional to label lengthpdf() functionAlso see wgraph/2 options for saving the graph (save/1 and stem/1).
?- G = [1-2:50,2-3:100], assert( wg(G) ), ?- wg(M), wgraph_plot(M,[]). ?- M = [row(from,to,weight),row(1,2,50),row(2,3,100)], assert(wg0(M) ). ?- wg0(M), wgraph_plot(M,[]). ?- G = [row(from,to,weight),row(1,2,50),row(2,3,100),row(4,'','')], assert(wg1(G) ). ?- wg1(G1), wgraph_plot(G1,true). ?- G = [1-2:200,2-3:400,4], assert(wg1(G) ). ?- wg1(G1), wgraph_plot(G1,true). ?- wg1(G1), wgraph_plot(G1,orphan_edge_weight(0.1) ). ?- wg1(G1), wgraph_plot(G1,plotter(ggnet2) ).
?- G1=[1-2:200,2-3:400,4], wgraph_plot(G1, [format(svg),stem(g1),save(false),plotter(ggnet2)] ).
Produces file: g1.svg
[[../doc/images/g1.svg]]
Rgraph is the reduced graph after removing the clique of Nodes, with Weights being the nest list of removed weights.
?- G = [a-b:1,a-c:1,a-d:1,b-c:1,b-d:1,c-d:1,d-e:1], assert( wg(G) ). ?- wg(G), wgraph_clique([a,b,c,d],G). G = [a-b:1, a-c:1, a-d:1, b-c:1, b-d:1, c-d:1, d-e:1]. ?- wg(G), wgraph_clique([a,b,c,d],G,W,R). G = [a-b:1, a-c:1, a-d:1, b-c:1, b-d:1, c-d:1, d-e:1], W = [[1, 1, 1], [1, 1], [1], []], R = [d-e:1].
When constructing a Wgraph, Weights can be a single atomic, or a list of atomic value and
Wgraph edges (Nd1-Nd2:Wgt). If a single atomic value (also works if a singleton atomic is given),
then all weights are set to this atomic. When a list given then for each Ugraph Nd1-Nd2, Nd1-Nd2:Wgt is looked for in Weights, and if found Wgt is used. Else the first atomic in the list is used.
If no atomic is given in the list, default is 1. Which is also the default if no Weights
is given (wgraph_ugraph(-,+).
?- wgraph_ugraph( [1-2:1,1-3:2,2-3:4], Ug ).
Ug = [1-[2, 3], 2-[3], 3-[]].
?- wgraph_ugraph( [1-2:1,1-3:2,2-3:1,4], Ug ).
Ug = [1-[2, 3], 2-[3], 3-[], 4-[]].
?- wgraph_ugraph( [1-2:1,1-3:2,2-3:1,4], Ug ), wgraph_ugraph( Wg, Ug ).
Ug = [1-[2, 3], 2-[3], 3-[], 4-[]],
Wg = [4, 1-2:1, 1-3:1, 2-3:1].
?-
Org = [1-2:1,1-3:2,2-3:1,4],
wgraph_ugraph( Org, Ug ), del_vertices( Ug, [2], Del ),
wgraph_ugraph( New, Org, Del ).
Org = [1-2:1, 1-3:2, 2-3:1, 4],
Ug = [1-[2, 3], 2-[3], 3-[], 4-[]],
Del = [1-[3], 3-[], 4-[]],
New = [4, 1-3:2].
?- wgraph_vertices( [a-b:3,b-c:4], Nodes ). Nodes = [a, b, c]. ?- wgraph_vertices( [a-b:3,b-c:4,d], Nodes ). Nodes = [a, b, c, d].
?- wgraph_adjacency( [a-b:2,b-c:3,c-a:1], wga ).
?- <- wga.
[,1] [,2] [,3]
[1,] 0 2 0
[2,] 0 0 3
[3,] 1 0 0
true.
?- wgraph_add_edges( [], a-b:1, One ), wgraph_add_edges( One, b-c:2, Two ), wgraph_add_edges( Three, a-c:3, Three ).
?- wgraph_add_vertices( [1-3:1], [2,3], New ). New = [2, 1-3:1].
Opts
cliques(Cliques)
either a Clique-Members list, or /2 predicate holding Member, Clique relations
replace_requires(RR=all_present)
i think this is min_pop_present actually
min_pop(MinPop=4)
how many of the clique members have to be present for replace to take place
The predicate follows name and argument conventions from del_vertices/3. However, Vertices can be a single Vertex here (non-list).
?-
wgraph_del_vertices( [a,b-c:1,b-d:2], d, G1 ).
G1 = [a, b-c:1].
?-
wgraph_del_vertices( [a,b-c:1,b-d:2], [c,d], G2 ).
G2 = [a].
?-
wgraph_vertex_frequencies( [a,b-c:1,b-d:2], Freqs1 ).
Freqs1 = [a-0, b-2, c-1, d-1].
Only
?-
wgraph_vertices_collapse( [a,b-c:1,b-d:2], [d,c], e, G1 ).
G1 = [a, b-e:2].
?-
wgraph_vertices_collapse( [a,b-c:1,b-d:2,e], [a,e], f, G2 ).
date(Y,M,D)).
?- wgraph_version( V, D ). V = 0:7:0 D = date(2022, 12, 29)