wgraph.pl -- Weighted graphs, with plotting function via Real

For now the emphasis is on plotting via igraph and qgraph R libraries via Real.

A weighted graphs is reepresented as a list of From-To:W edges or Node entries for orphans.

See wgraph_plot/2.

author
- nicos angelopoulos
version
- 0.1 2015/6/12
- 0:2 2016/1/23
- 0.3 2017/3/12
wgraph(+InGraph, -Graph)
wgraph(+OutF, +Graph)
wgraph(+OutF, +Graph, +Opts)
Graph is the wgraph/1 canonical representation of InGraph. InGraph, can be either a wgraph or a csv file that has columns 'from', 'to' and 'weight'. The latter case needs 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

cnm_from(From=from)
name for from column
cnm_to(To=to)
name for to column
cnm_weight(Weight=weight)
name for weight column
save(Save=false)
to save wgraph in csv file, defaults to true if Stem is given
stem(Stem=wgraph)
stem for saving
 ?- 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.

wgraph_plot(+Wgraph, +Opts)
Display weighed graph Wgraph from a layout that may include colours and labels. Wgraph should be in a form accepted by wgraph/3.

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 should 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

Ropt = Rval
= paired options are passed to the plotter call, see r_call/2
cnm_colour(Clrs=colour)
= (layout) colours column name
cnm_label(Lbs=label)
(layout) labels column name
cnm_x(Xc=x)
(layout) column name for X position coordinate
cnm_y(Yc=y)
(layout) column name for Y position coordinate
cnm_from(From=from)
(graph) column name for From column
cnm_to(To=to)
(graph) column name for To column
cnm_weight(Wc=weight)
(graph) column name for edge weight
colours(Clrs="white")
colours for the nodes - should be known to R
format(Form=x11)
output format: pdf, x11 or none (as x11 without explicit <- x11() call
labels(Lbs=[110,111,100,101,115])
labels for the nodes, _[]_ for none, false for leaving it unset
layout_call(LayG)
layout R/qgraph function to use for getting x,y coordinates. defaults to... which is only used if layout_mtx(LayM) is also missing
layout_mtx(LayM)
used if layout_call(LayG) is not present
orphan_edge_weight(OEW)
if present an edge is added for every orphan from a medianed node with this weight
plotter(Plotter=qgraph)
or igraph
save(Save=true)
to save the layout and graph, defaults to false if no stem is given
stem(Stem)
stem of the output file (def. replaces .csv to .pdf if LayM is a file- else wgraph_plot)
height(H=7)
height of the plot device
width(W=7)
width of the plot device
label_distance(LbD=0.5)
distance for vertex labels
node_size(Vz)
size of nodes, can be prop(Min,Mult)- size being proportional to label length
wgraph(Wgraph)
the weighed graph (wgraph/1)
wgraph_mtx(WgMtx)
the matrix from which to extract the graph if one is not given by Wgraph
w_threshold(Thres=1)
values below that are not ajusted for width

Also 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) ).
author
- nicos angelopoulos
version
- 0.1 2014/11/21
- 0.2 2016/01/23
wgraph_clique(+Nodes, +Wgraph)
wgraph_clique(+Nodes, +Wgraph, -Weights, -Rgraph)
True iff Nodes form a clique in Wgraph. Currently only testing is implemented.

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].
author
- nicos angelopoulos
version
- 0.1 2015/3/30
wgraph_ugraph(+Wgraph, -Ugraph)
wgraph_ugraph(-Wgraph, +Ugraph)
Convert between wgraph and ugraph representations.

Add this as a speical case of wgraph/2 ?

 ?- 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_vertices(+Wgraph, -Vertices)
Nodes is the set of all nodes in Wgraph (wgraph/1).
 ?- 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].
author
- nicos angelopoulos
version
- 0.1 2014/11/13
wgraph_adjacency(+Wgraph, +Nodes, +Rmtx)
wgraph_adjacency(+Wgraph, +Rmtx)
Create and occupy R matrix Rmtx as the weighed adjacency matrix of Wgraph (wgraph/1). When present Nodes is used to define the shape and location of nodes in Rmtx. Else the set of N1 and N2s in Wgraph is used (see wgraph_vertices/2).
 ?- 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.
author
- nicos angelopoulos
version
- 0.1 2014/11/13
wgraph_add_edges(+Graph, +Edges, -NewGraph)
Add edges to a graph. NewGraph is sorted.
?- wgraph_add_edges( [], a-b:1, One ), wgraph_add_edges( One, b-c:2, Two ), wgraph_add_edges( Three, a-c:3, Three ).
author
- nicos angelopoulos
version
- 0.1 2015/3/30
wgraph_add_vertices(+Graph, +Verts, -NewGraph)
?- wgraph_add_vertices( [1-3:1], [2,3], New ).
New = [2, 1-3:1].
wgraph_known_cliques_replace(+Wgraph, -Cgraph, -Fired, +Opts)
Replace edges of cliques with central nodes from which edges eminate to all present members. Non clique nodes that connect to all present nodes point to the central node, else their connections are untouched. Fired is a list of Clq-Set pairs, where Clq is a new node and Set is the set of all nodes connecting to Clq.
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
author
- nicos angelopoulos
version
- 0.1 2015/3/30
To be done
- complete(Comp) flag
- alternative implementations of replace_requires(RR) flag
wgraph_version(-Version, -Date)
Version (Mj:Mn:Fx) and Date of publication (date(Y,M,D)).
 ?- wgraph_version( V, D ).
 V = 0:3:0
 D = date(2017,3,2)