From: Andrej V. <an...@us...> - 2008-11-03 09:44:22
|
Update of /cvsroot/maxima/maxima/share/contrib/graphs In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv10767/share/contrib/graphs Modified Files: spring_embedding.lisp graph_core.lisp graph_polynomials.mac graph6.lisp draw_graph.mac graphio.mac demoucron.lisp isomorphism.lisp Log Message: Corrected graph_size/graph_order functions. Index: spring_embedding.lisp =================================================================== RCS file: /cvsroot/maxima/maxima/share/contrib/graphs/spring_embedding.lisp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- spring_embedding.lisp 30 Oct 2008 16:22:15 -0000 1.6 +++ spring_embedding.lisp 3 Nov 2008 09:44:14 -0000 1.7 @@ -74,7 +74,7 @@ (vertex-displacement (make-hash-table)) (*fixed-vertices* (cdr fixed-vertices)) (*optimal-distance* (/ (* 2 *frame-width*) - (sqrt ($graph_size g))))) + (sqrt ($graph_order g))))) (random-positions (vertices g) dimension) Index: graph_core.lisp =================================================================== RCS file: /cvsroot/maxima/maxima/share/contrib/graphs/graph_core.lisp,v retrieving revision 1.19 retrieving revision 1.20 diff -u -d -r1.19 -r1.20 --- graph_core.lisp 21 Oct 2008 10:48:59 -0000 1.19 +++ graph_core.lisp 3 Nov 2008 09:44:14 -0000 1.20 @@ -75,8 +75,8 @@ (cond ((graph-p gr) (format t "~%Graph on ~d vertices with ~d edges." - (graph-size gr) (graph-order gr)) - (when (> (graph-size gr) 0 ) + (graph-order gr) (graph-size gr)) + (when (> (graph-order gr) 0 ) (format t "~%Adjacencies:")) (dolist (v (graph-vertices gr)) (format t "~% ~2d :" v) @@ -84,8 +84,8 @@ (format t " ~2d" u)))) (t (format t "~%Digraph on ~d vertices with ~d arcs." - (digraph-size gr) (digraph-order gr)) - (when (> (digraph-size gr) 0 ) + (digraph-order gr) (digraph-size gr)) + (when (> (digraph-order gr) 0 ) (format t "~%Adjacencies:")) (dolist (v (digraph-vertices gr)) (format t "~% ~2d :" v) @@ -103,18 +103,18 @@ (defun $is_graph_or_digraph (x) (or (graph-p x) (digraph-p x))) -(defun $graph_size (gr) - (require-graph-or-digraph 'graph_size 1 gr) - (if (graph-p gr) - (graph-size gr) - (digraph-size gr))) - (defun $graph_order (gr) (require-graph-or-digraph 'graph_order 1 gr) (if (graph-p gr) (graph-order gr) (digraph-order gr))) +(defun $graph_size (gr) + (require-graph-or-digraph 'graph_size 1 gr) + (if (graph-p gr) + (graph-size gr) + (digraph-size gr))) + (defun $copy_graph (gr) (require-graph-or-digraph 'copy_graph 1 gr) (if (graph-p gr) @@ -208,12 +208,12 @@ (defun add-vertex (i gr) (if (graph-p gr) (progn - (incf (graph-size gr)) + (incf (graph-order gr)) (push i (graph-vertices gr)) (setf (graph-vertex-positions gr) nil) (setf (gethash i (graph-neighbors gr)) ())) (progn - (incf (digraph-size gr)) + (incf (digraph-order gr)) (push i (digraph-vertices gr)) (setf (digraph-vertex-positions gr) nil) (setf (gethash i (digraph-in-neighbors gr)) ()) @@ -281,7 +281,7 @@ (setf (graph-vertex-positions gr) nil) (setf (graph-vertices gr) (remove v (graph-vertices gr) :count 1)) (remhash v (graph-neighbors gr)) - (decf (graph-size gr))) + (decf (graph-order gr))) (progn (dolist (u (out-neighbors v gr)) (remove-edge (list v u) gr)) @@ -292,20 +292,20 @@ (setf (digraph-vertices gr) (remove v (digraph-vertices gr) :count 1)) (remhash v (digraph-in-neighbors gr)) (remhash v (digraph-out-neighbors gr)) - (decf (digraph-size gr)))) + (decf (digraph-order gr)))) '$done) (defun $first_vertex (gr) (require-graph-or-digraph 'first_vertex 1 gr) (cond - ((= 0 (if (graph-p gr) (graph-size gr) (digraph-size gr))) + ((= 0 (if (graph-p gr) (graph-order gr) (digraph-order gr))) ($error "first_vertex: no first vertex in an empty graph.")) (t (first (vertices gr))))) (defun $max_degree (gr) (require-graph 'max_degree 1 gr) (cond - ((= 0 (graph-size gr)) + ((= 0 (graph-order gr)) ($error "max_degree: no max degree in an empty graph.")) (t (let* ((v (first (graph-vertices gr))) (d (length (neighbors v gr)))) @@ -318,7 +318,7 @@ (defun $min_degree (gr) (require-graph 'min_degree 1 gr) (cond - ((= 0 (graph-size gr)) + ((= 0 (graph-order gr)) ($error "min_degree: no min degree in an empty graph.")) (t (let* ((v (first (graph-vertices gr))) (d (length (neighbors v gr)))) @@ -330,7 +330,7 @@ (defun $average_degree (gr) (require-graph 'average_degee 1 gr) - (m* 2 (m// (graph-order gr) (graph-size gr)))) + (m* 2 (m// (graph-size gr) (graph-order gr)))) (defun $vertex_degree (v gr) (require-vertex 'vertex_degree 1 v) @@ -461,12 +461,12 @@ (push v (gethash u (graph-neighbors gr))) (push u (gethash v (graph-neighbors gr))) (push e (graph-edges gr)) - (incf (graph-order gr))) + (incf (graph-size gr))) (progn (push v (gethash u (digraph-out-neighbors gr))) (push u (gethash v (digraph-in-neighbors gr))) (push e (digraph-edges gr)) - (incf (digraph-order gr)))) + (incf (digraph-size gr)))) '$done)) (defun add-edges (elist gr) @@ -511,7 +511,7 @@ (setf (gethash v (graph-neighbors gr)) (remove u (gethash v (graph-neighbors gr)) :count 1)) (clear-edge-weight e gr) - (decf (graph-order gr)) + (decf (graph-size gr)) (setf (graph-edges gr) (remove `(,u ,v) (graph-edges gr) :test #'equal :count 1))) (progn @@ -520,7 +520,7 @@ (setf (gethash v (digraph-in-neighbors gr)) (remove u (gethash v (digraph-in-neighbors gr)) :count 1)) (clear-edge-weight e gr) - (decf (digraph-order gr)) + (decf (digraph-size gr)) (setf (digraph-edges gr) (remove `(,u ,v) (digraph-edges gr) :test #'equal :count 1)))) '$done)) @@ -800,7 +800,18 @@ (add-edge `(,i ,j) g)))) g)) -(defun $graph_union (g1 g2) +(defun $graph_union (&rest gr-list) + (cond + ((= 0 (length gr-list)) + ($empty_graph 0)) + ((= 1 (length gr-list)) + (first gr-list)) + ((= 2 (length gr-list)) + (graph-union (first gr-list) (second gr-list))) + (t + (graph-union (first gr-list) (apply #'$graph_union (rest gr-list)))))) + +(defun graph-union (g1 g2) (require-graph 'graph_union 1 g1) (require-graph 'graph_union 2 g2) (let ((g (make-graph)) (n (1+ (apply #'max (graph-vertices g1))))) @@ -821,14 +832,25 @@ (setq i (1+ i))) names)) -(defun $graph_product (g1 g2) +(defun $graph_product (&rest gr-list) + (cond + ((= 0 (length gr-list)) + ($empty_graph 0)) + ((= 1 (length gr-list)) + (first gr-list)) + ((= 2 (length gr-list)) + (graph-product (first gr-list) (second gr-list))) + (t + (graph-product (first gr-list) (apply #'$graph_product (rest gr-list)))))) + +(defun graph-product (g1 g2) (require-graph 'graph_product 1 g1) (require-graph 'graph_product 2 g2) (let* ((names1 (get-canonical-names (graph-vertices g1))) (names2 (get-canonical-names (graph-vertices g2))) - (size1 (graph-size g1)) - (size2 (graph-size g2)) + (size1 (graph-order g1)) + (size2 (graph-order g2)) (size (* size1 size2)) (g ($empty_graph size))) (dolist (e (graph-edges g1)) @@ -854,7 +876,7 @@ (defun $line_graph (gr) (require-graph 'line_graph 1 gr) (let* ((edge-list - (get-canonical-names (graph-edges gr))) (n (graph-order gr)) + (get-canonical-names (graph-edges gr))) (n (graph-size gr)) (g ($empty_graph n))) (dotimes (i n) (do ((j (1+ i) (1+ j))) @@ -1061,7 +1083,7 @@ (defun $connected_components (gr) (require-graph 'connected_components 1 gr) - (when (= 0 (graph-size gr)) + (when (= 0 (graph-order gr)) (return-from $connected_components '((mlist simp)))) (let ((components ()) (visited (make-hash-table))) (loop for v in (vertices gr) do @@ -1084,7 +1106,7 @@ (defun $is_tree (gr) (require-graph 'is_tree 1 gr) - (and ($is_connected gr) (= (graph-size gr) (1+ (graph-order gr))))) + (and ($is_connected gr) (= (graph-order gr) (1+ (graph-size gr))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; @@ -1096,7 +1118,7 @@ (require-graph-or-digraph 'reachable_vertices 2 gr) (require-vertex 'reachable_vertices 1 v) (require-vertex-in-graph 'reachable_vertices v gr) - (when (= 0 (if (graph-p gr) (graph-size gr) (digraph-size gr))) + (when (= 0 (if (graph-p gr) (graph-order gr) (digraph-order gr))) (return-from $reachable_vertices '((mlist simp)))) (let ((component ()) (visited (make-hash-table))) (unless (gethash v visited) @@ -1118,7 +1140,7 @@ (defun $adjacency_matrix (gr) (require-graph-or-digraph 'adjacency_matrix 1 gr) - (let* ((n (if (graph-p gr) (graph-size gr) (digraph-size gr))) + (let* ((n (if (graph-p gr) (graph-order gr) (digraph-order gr))) (m ($zeromatrix n n)) (names (get-canonical-names (vertices gr)))) (dolist (e (edges gr)) @@ -1131,7 +1153,7 @@ (defun $laplacian_matrix (gr) (require-graph 'laplacian_matrix 1 gr) - (let ((m ($zeromatrix (graph-size gr) (graph-size gr))) + (let ((m ($zeromatrix (graph-order gr) (graph-order gr))) (names (get-canonical-names (vertices gr)))) (dolist (v (graph-vertices gr)) (setf (nth (1+ (cdr (assoc v names))) @@ -1168,7 +1190,7 @@ (girth gr t)) (defun girth (gr odd) - (let ((girth (1+ (graph-size gr)))) + (let ((girth (1+ (graph-order gr)))) (dolist (v (graph-vertices gr)) (let ((visited (new-set v)) @@ -1193,7 +1215,7 @@ (setq girth (min girth (* 2 depth)))))))) (setq active next) (setq depth (1+ depth))))) - (if (> girth (graph-size gr)) + (if (> girth (graph-order gr)) '$inf girth))) @@ -1245,7 +1267,7 @@ (defun $radius (gr) (require-graph 'radius 1 gr) (let ((ecc (eccentricity (vertices gr) gr)) - (radius ($graph_size gr))) + (radius ($graph_order gr))) (maphash #'(lambda (key val) (declare (ignore key)) (when (< val radius) @@ -1257,7 +1279,7 @@ (require-graph 'graph_center 1 gr) (let ((ecc (eccentricity (vertices gr) gr)) (per ()) - (radius ($graph_size gr))) + (radius ($graph_order gr))) (maphash #'(lambda (key val) (declare (ignore key)) (when (< val radius) @@ -1292,7 +1314,7 @@ (defun $bipartition (gr) (require-graph 'bipartition 1 gr) - (when (= (graph-size gr) 0) + (when (= (graph-order gr) 0) (return-from $bipartition `((mlist simp) ((mlist simp)) ((mlist simp))))) (let ((components (cdr ($connected_components gr))) (A ()) (B ())) (dolist (c components) @@ -1345,7 +1367,7 @@ (defun $biconnected_components (gr) (require-graph 'biconnected_components 1 gr) - (if (= 0 (graph-size gr)) + (if (= 0 (graph-order gr)) `((mlist simp)) (let ((bicomp `((mlist simp))) @@ -1426,7 +1448,7 @@ (defun $strong_components (gr) (require-digraph 'strong_components 1 gr) - (if (= 0 (digraph-size gr)) + (if (= 0 (digraph-order gr)) `((mlist simp)) (let ((res)) (setq *scon-low* (make-hash-table)) @@ -1478,7 +1500,7 @@ (require-digraph 'topological_sort 1 dag) (let ((in-degrees (make-hash-table)) (q ()) - (n ($graph_order dag)) + (n ($graph_size dag)) (s ())) (dolist (v (vertices dag)) (setf (gethash v in-degrees) 0)) @@ -1688,8 +1710,8 @@ (if (null *hamilton-cycle*) (progn (if (= (length part) (if (graph-p gr) - (graph-size gr) - (digraph-size gr))) + (graph-order gr) + (digraph-order gr))) (if (member (car (last part)) (neighbors (first part) gr)) (setq *hamilton-cycle* (append (last part) part)))) (dolist (v (neighbors (car part) gr)) @@ -1730,7 +1752,7 @@ (defun greedy-color (gr) (let ((coloring (make-hash-table)) (available-colors (make-hash-table)) (tmp ())) - (dotimes (i (graph-size gr)) + (dotimes (i (graph-order gr)) (push i tmp)) (setq tmp (reverse tmp)) (dolist (v (graph-vertices gr)) @@ -1747,7 +1769,7 @@ (require-graph 'max_clique 1 gr) (setq *maximum-clique* ()) (let ((v) (coloring) (h ($copy_graph gr))) - (do () ((>= (length *maximum-clique*) (graph-size h))) + (do () ((>= (length *maximum-clique*) (graph-order h))) (setq coloring (greedy-color h)) (setq v ($second ($max_degree h))) (extend-clique `(,v) (neighbors v h) coloring h) @@ -1820,7 +1842,7 @@ (defun $edge_coloring (gr) (require-graph 'edge_coloring 1 gr) (let* ((edge-list (get-canonical-names (graph-edges gr))) - (n (graph-order gr)) + (n (graph-size gr)) (g ($empty_graph n))) (dotimes (i n) (do Index: graph_polynomials.mac =================================================================== RCS file: /cvsroot/maxima/maxima/share/contrib/graphs/graph_polynomials.mac,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- graph_polynomials.mac 27 Oct 2007 09:06:28 -0000 1.2 +++ graph_polynomials.mac 3 Nov 2008 09:44:14 -0000 1.3 @@ -27,16 +27,16 @@ *********************/ chromatic_polynomial(gr, x) := -if graph_order(gr)=0 then x^graph_size(gr) +if graph_size(gr)=0 then x^graph_order(gr) else block( [comp], comp : connected_components(gr), if length(comp)>1 then ( comp : map(lambda([u], chromatic_polynomial(induced_subgraph(u, gr), x)), comp), expand(apply("*", comp))) - else if graph_order(gr)=graph_size(gr)-1 then x*(x-1)^graph_order(gr) - else if graph_order(gr)=graph_size(gr)*(graph_size(gr)-1)/2 then c_poly_complete(graph_size(gr),x) - else if min_degree(gr)[1]=2 and max_degree(gr)[1]=2 then c_poly_cycle[graph_size(gr)](x) + else if graph_size(gr)=graph_order(gr)-1 then x*(x-1)^graph_size(gr) + else if graph_size(gr)=graph_order(gr)*(graph_order(gr)-1)/2 then c_poly_complete(graph_order(gr),x) + else if min_degree(gr)[1]=2 and max_degree(gr)[1]=2 then c_poly_cycle[graph_order(gr)](x) else block( [g1, g2, u, v, p1, p2, e], u : max_degree(gr)[2], Index: graph6.lisp =================================================================== RCS file: /cvsroot/maxima/maxima/share/contrib/graphs/graph6.lisp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- graph6.lisp 27 Oct 2007 09:06:28 -0000 1.1 +++ graph6.lisp 3 Nov 2008 09:44:14 -0000 1.2 @@ -64,7 +64,7 @@ (graph6-string gr)) (defun graph6-string (gr) - (let ((n ($graph_size gr)) + (let ((n ($graph_order gr)) (names (get-canonical-names (vertices gr))) (e-val)) @@ -247,7 +247,7 @@ (defun sparse6-string (gr) (let* ((vrt (reverse (vertices gr))) - (n ($graph_size gr)) + (n ($graph_order gr)) (k (integer-length (1- n))) (names (get-canonical-names vrt)) (edges (mapcar #'(lambda (u) (list (cdr (assoc (first u) names)) Index: draw_graph.mac =================================================================== RCS file: /cvsroot/maxima/maxima/share/contrib/graphs/draw_graph.mac,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- draw_graph.mac 30 Oct 2008 16:22:15 -0000 1.14 +++ draw_graph.mac 3 Nov 2008 09:44:14 -0000 1.15 @@ -26,12 +26,12 @@ if draw_loaded#true then load("draw")$ circular_positions(G) := block( - [v_list, numer : true, n : graph_size(G)], + [v_list, numer : true, n : graph_order(G)], v_list : vertices(G), makelist( [v_list[i+1], [2+cos(2*i*%pi/n), 2+sin(2*i*%pi/n)]], - i, 0, graph_size(G)-1))$ + i, 0, graph_order(G)-1))$ write_file(G) := block( [display2d:false, file, e], @@ -284,7 +284,11 @@ 'line_width = edge_width, 'points_joined = true, 'head_length = head_length, - 'head_angle = head_angle + 'head_angle = head_angle, + 'axis_3d = false, + 'xtics = false, + 'ytics = false, + 'ztics = false ], edges, [ Index: graphio.mac =================================================================== RCS file: /cvsroot/maxima/maxima/share/contrib/graphs/graphio.mac,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- graphio.mac 22 Apr 2008 08:48:58 -0000 1.7 +++ graphio.mac 3 Nov 2008 09:44:14 -0000 1.8 @@ -29,9 +29,9 @@ for c in comments do ( printf(fl, "c ~a~%", c)), if is_graph(gr) then - printf(fl, "p edges ~a ~a~%", graph_size(gr), graph_order(gr)) + printf(fl, "p edges ~a ~a~%", graph_order(gr), graph_size(gr)) else - printf(fl, "p arcs ~a ~a~%", graph_size(gr), graph_order(gr)), + printf(fl, "p arcs ~a ~a~%", graph_order(gr), graph_size(gr)), for v in vertices(gr) do ( if get_vertex_label(v, gr)#false then printf(fl, "n ~a ~a~%", get_hash(v, names), get_vertex_label(v, gr))), Index: demoucron.lisp =================================================================== RCS file: /cvsroot/maxima/maxima/share/contrib/graphs/demoucron.lisp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- demoucron.lisp 22 Mar 2008 10:51:30 -0000 1.2 +++ demoucron.lisp 3 Nov 2008 09:44:14 -0000 1.3 @@ -286,7 +286,7 @@ (defun demoucron (g return-walks) - (when (> ($graph_order g) (- (* 3 ($graph_size g)) 6)) + (when (> ($graph_size g) (- (* 3 ($graph_order g)) 6)) (return-from demoucron nil)) (let ((*h-vertices*) @@ -389,13 +389,13 @@ (defun $is_planar (gr) (require-graph 'is_planar 1 gr) - (when (< ($graph_size gr) 5) + (when (< ($graph_order gr) 5) (return-from $is_planar t)) - (when (> ($graph_order gr) (- (* 3 ($graph_size gr)) 6)) + (when (> ($graph_size gr) (- (* 3 ($graph_order gr)) 6)) (return-from $is_planar nil)) (unless ($is_connected gr) (return-from $is_planar (is-planar-unconnected gr))) - (when (< ($graph_order gr) ($graph_size gr)) ;; gr is a tree + (when (< ($graph_size gr) ($graph_order gr)) ;; gr is a tree (return-from $is_planar t)) (let ((bicomponents ($biconnected_components gr))) (loop for c in (cdr bicomponents) do Index: isomorphism.lisp =================================================================== RCS file: /cvsroot/maxima/maxima/share/contrib/graphs/isomorphism.lisp,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- isomorphism.lisp 11 Aug 2008 17:16:44 -0000 1.5 +++ isomorphism.lisp 3 Nov 2008 09:44:14 -0000 1.6 @@ -20,8 +20,8 @@ (defun $is_isomorphic (gr1 gr2) - (and (= ($graph_size gr1) ($graph_size gr2)) - (= ($length ($isomorphism gr1 gr2)) ($graph_size gr1)))) + (and (= ($graph_order gr1) ($graph_order gr2)) + (= ($length ($isomorphism gr1 gr2)) ($graph_order gr1)))) (defun $isomorphism (gr1 gr2) (cond ((graph-p gr1) @@ -72,7 +72,7 @@ (defun extend-isomorphism-graphs (mapping m1 m2 out1 out2 gr1 gr2) ;; check if we have found an isomorphism - (when (= (length m1) ($graph_size gr1)) + (when (= (length m1) ($graph_order gr1)) (return-from extend-isomorphism-graphs mapping)) ;; try extending the mapping @@ -175,7 +175,7 @@ (defun extend-isomorphism-digraphs (mapping m1 m2 out1 out2 in1 in2 gr1 gr2) ;; check if we have found an isomorphism - (when (= (length m1) ($graph_size gr1)) + (when (= (length m1) ($graph_order gr1)) (return-from extend-isomorphism-digraphs mapping)) ;; try extending the mapping |