/** * get label for given $edge * * @param Edge $edge * @return string label (may be empty if there's nothing to be described) */ protected function getEdgeLabel(Edge $edge) { $label = ''; $flow = $edge->getFlow(); $capacity = $edge->getCapacity(); // flow is set if ($flow !== NULL) { // NULL capacity = infinite capacity $label = $flow . '/' . ($capacity === NULL ? '∞' : $capacity); // capacity set, but not flow (assume zero flow) } elseif ($capacity !== NULL) { $label = '0/' . $capacity; } $weight = $edge->getWeight(); // weight is set if ($weight !== NULL) { if ($label === '') { $label = $weight; } else { $label .= '/' . $weight; } } return $label; }
/** * create new clone of the given edge between adjacent vertices * * @param Edge $originalEdge original edge from old graph * @param int $ia index of start vertex * @param int $ib index of end vertex * @return Edge new edge in this graph * @uses Edge::getVertices() * @uses Graph::getVertex() * @uses Vertex::createEdge() to create a new undirected edge if given edge was undrected * @uses Vertex::createEdgeTo() to create a new directed edge if given edge was directed * @uses Edge::getWeight() * @uses Edge::setWeight() * @uses Edge::getFlow() * @uses Edge::setFlow() * @uses Edge::getCapacity() * @uses Edge::setCapacity() */ private function createEdgeCloneInternal(Edge $originalEdge, $ia, $ib) { $ends = $originalEdge->getVertices()->getIds(); // get start vertex from old start vertex id $a = $this->getVertex($ends[$ia]); // get target vertex from old target vertex id $b = $this->getVertex($ends[$ib]); if ($originalEdge instanceof EdgeDirected) { $newEdge = $a->createEdgeTo($b); } else { // create new edge between new a and b $newEdge = $a->createEdge($b); } // TODO: copy edge attributes $newEdge->getAttributeBag()->setAttributes($originalEdge->getAttributeBag()->getAttributes()); $newEdge->setWeight($originalEdge->getWeight()); $newEdge->setFlow($originalEdge->getFlow()); $newEdge->setCapacity($originalEdge->getCapacity()); return $newEdge; }
protected function getLayoutEdge(Edge $edge) { $layout = $edge->getLayout(); // use flow/capacity/weight as edge label $label = NULL; $flow = $edge->getFlow(); $capacity = $edge->getCapacity(); // flow is set if ($flow !== NULL) { // NULL capacity = infinite capacity $label = $flow . '/' . ($capacity === NULL ? '∞' : $capacity); // capacity set, but not flow (assume zero flow) } elseif ($capacity !== NULL) { $label = '0/' . $capacity; } $weight = $edge->getWeight(); // weight is set if ($weight !== NULL) { if ($label === NULL) { $label = $weight; } else { $label .= '/' . $weight; } } if ($label !== NULL) { if (isset($layout['label'])) { $layout['label'] .= ' ' . $label; } else { $layout['label'] = $label; } } return $layout; }