Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.3.0

Request #6630 Multiple edges between 2 nodes
Submitted: 2006-01-30 12:48 UTC
From: ogmueller Assigned: sebastian
Status: Closed Package: Image_GraphViz (version 1.1.0)
PHP Version: 4.4.2 OS:
Roadmaps: (Not assigned)    
Subscription  


 [2006-01-30 12:48 UTC] ogmueller
Description: ------------ It would be nice to have multiple edges between 2 nodes. I saw that you have commented the addEdge() function with "This cannot handle multiple identical edges", but it would be nice to have this feature. I have tried to implement it myself and it seems to work by changing addEdge(), removeEdge() and parse() as follows: ### add edge ### function addEdge($edge, $attributes = array()) { if (is_array($edge)) { $from = key($edge); $to = reset($edge); $this->graph['edges'][$from][] = $to; // set pointer to last element in order to get the last key end($this->graph['edges'][$from]); $id = $from . '_' . $to . '_' . key($this->graph['edges'][$from]); if (is_array($attributes)) { $this->graph['edgeAttributes'][$id] = $attributes; } } } ### remove edge ### function removeEdge($edge) { if (is_array($edge)) { $from = key($edge); $to = current($edge); // remove all edges between the two nodes (might be more than one) while( false !== ($number = array_search($to, $this->graph['edges'][$from])) ) { $id = $from . '_' . $to . '_' . $number; if (isset($this->graph['edges'][$from][$number])) { unset($this->graph['edges'][$from][$number]); } if (isset($this->graph['edgeAttributes'][$id])) { unset($this->graph['edgeAttributes'][$id]); } } } } ### piece of parse section ### if (isset($this->graph['edges'])) { foreach($this->graph['edges'] as $from => $nodeList) { foreach($nodeList as $number => $to) { unset($attributeList); $label = $from . '_' . $to . '_' . $number; foreach($this->graph['edgeAttributes'][$label] as $key => $value) { $attributeList[] = $key . '="' . $value . '"'; } $parsedGraph .= sprintf( '"%s" -> "%s"', addslashes(stripslashes($from)), addslashes(stripslashes($to)) ); if (!empty($attributeList)) { $parsedGraph .= sprintf( ' [ %s ]', implode(',', $attributeList) ); } $parsedGraph .= ";\n"; } // foreach } // foreach }

Comments

 [2007-11-16 16:34 UTC] jausions (Philippe Jausions)
I agree that there's no true reason behind NOT supporting multiedges between same nodes. Especially the following code in addEdge() doesn't make any sense to me (what is the purpose of the array_merge, as this is not used anywhere else in the code): <code> if (!isset($this->graph['edges'][$id])) { $this->graph['edges'][$id] = $edge; } else { $this->graph['edges'][$id] = array_merge( $this->graph['edges'][$id], $edge ); } </code> I will try to put a patch together to allow multi-edges, while preserving current (odd) behavior ("Strict" Digraph?)
 [2007-11-18 02:20 UTC] jausions (Philippe Jausions)
Patch available below along with patched class file and some test files (although not .phpt yet) http://pear.11abacus.com/dev/Image/GraphViz/ (the patch file itself is too big to be attached here) Fixes Bug #4924, Req #6630, Req #8295, Bug #10753.
 [2007-11-19 07:12 UTC] sebastian (Sebastian Bergmann)
Thank you for your bug report. This issue has been fixed in the latest released version of the package, which you can download at http://pear.php.net/get/Image_GraphViz