-
Notifications
You must be signed in to change notification settings - Fork 2
/
typed-edge-graph-methods.lisp
65 lines (57 loc) · 2.2 KB
/
typed-edge-graph-methods.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
(in-package #:graph-utils)
(declaim (optimize (speed 3) (space 2)))
(defmethod in-degree ((graph typed-graph) (node integer) &key edge-type)
(let ((degree 0) (matrix (gethash edge-type (matrix graph))))
(map-sarray-col #'(lambda (i w)
(declare (ignore i))
(when (> w 0)
(incf degree)))
matrix node)
degree))
(defmethod in-degree ((graph typed-graph) node &key edge-type)
(in-degree graph (lookup-node graph node) :edge-type edge-type))
(defmethod out-degree ((graph typed-graph) (node integer) &key edge-type)
(let ((degree 0) (matrix (gethash edge-type (matrix graph))))
(map-sarray-row #'(lambda (i w)
(declare (ignore i))
(when (> w 0)
(incf degree)))
matrix node)
degree))
(defmethod out-degree ((graph typed-graph) node &key edge-type)
(out-degree graph (lookup-node graph node) :edge-type edge-type))
(defmethod degree-distribution ((graph typed-graph) &key edge-type)
(let ((dist nil) (matrix (gethash edge-type (matrix graph))))
(maphash #'(lambda (node id)
(declare (ignore node))
(let ((degree 0))
(loop
for i
from 0
to (1- (row-count matrix)) do
(when (not (zerop (saref matrix id i)))
(incf degree)))
(if (assoc degree dist)
(incf (cdr (assoc degree dist)))
(push (cons degree 1) dist))))
(nodes graph))
(sort dist #'< :key 'car)))
(defmethod in-degree-distribution ((graph typed-graph) &key edge-type)
(let ((dist nil) (matrix (gethash edge-type (matrix graph))))
(maphash #'(lambda (node id)
(declare (ignore node))
(let ((degree 0))
(loop
for i
from 0
to (1- (col-count matrix)) do
(when (not (zerop (saref matrix i id)))
(incf degree)))
(if (assoc degree dist)
(incf (cdr (assoc degree dist)))
(push (cons degree 1) dist))))
(nodes graph))
(sort dist #'< :key 'car)))
(defmethod sim-rank ((graph typed-graph) n1 n2 &key edge-type)
(declare (ignore n1 n2 edge-type))
)