function dfs($graph, $current_key)
{
    static $explore = array();
    echo "Explored node {$current_key}<br/>";
    $explore[$current_key] = 1;
    foreach ($graph[$current_key] as $node_key => $is_vertex) {
        if ($is_vertex && !isset($explore[$node_key])) {
            dfs($graph, $node_key);
        }
    }
}
Пример #2
0
function dfs($n, $width, $left, $enabled)
{
    global $techs, $numLeaf, $town;
    echo "<div class = 'tech_hold' style = 'width:{$width}%;left:{$left}%'>";
    echo "<div style = 'background-color:" . ($enabled ? $town->techRes[$n] ? 'blue' : 'green' : 'gray') . "' class = 'tech_node'><span tech = '{$n}' teche = '" . ($enabled && !$town->techRes[$n]) . "'>{$techs[$n]->title}</span><div>{$techs[$n]->desc}<br /> Cost: {$techs[$n]->cost}<br /></div></div>";
    $numChild = count($techs[$n]->son);
    $width = intval(100 / $numChild);
    if ($n != 0x0) {
        echo "<div class = 'tech_horz_up'></div>";
    }
    if ($numChild > 0) {
        echo "<div class = 'tech_horz_down'></div>";
    } else {
        $numLeaf++;
    }
    echo "<div class = 'tech_vert' style = 'width:" . ($numChild - 1) * $width . "%;left:" . $width / 2 . "%'> </div><div class = 'tech_child' style = 'width:100%'>";
    if ($techs[$n]->son) {
        $i = 0;
        foreach ($techs[$n]->son as $s) {
            dfs($s, $width, $width * $i++, $town->techRes[$n]);
        }
    }
    echo "</div></div>";
}
Пример #3
0
function dfs($start_node, $path = array())
{
    global $pathes, $adj_matrix;
    if (empty($path)) {
        $path[] = $start_node;
    }
    if (array_key_exists($start_node, $adj_matrix)) {
        #print_r($adj_matrix[$start_node]);
        foreach ($adj_matrix[$start_node] as $child) {
            // child arr($nach, $value, $type_kante)
            $new_path = $path;
            // clone
            $new_path[] = $child[0];
            if (count($new_path) == 7) {
                // 6 Nodes Plus 1 value of the VU Edge
                $pathes[] = $new_path;
                // $pathes glob var
            } else {
                if ("vu" == $child[2]) {
                    // child arr($nach, $value, $type_kante)
                    $new_path[] = $child[1];
                    // stuff value inbetween node names
                }
                dfs($child[0], $new_path);
            }
        }
    }
}
Пример #4
-1
function dfs($a)
{
    global $ids;
    if (empty($a)) {
        return array();
    }
    $a['label'] = $a['name'];
    unset($a['name']);
    unset($a['data']);
    $a['id'] = findNum($a['id']);
    $ids[$a['label']] = $a['id'];
    if (!empty($a['children'])) {
        foreach ($a['children'] as &$or) {
            $or = dfs($or);
        }
    } else {
        unset($a['children']);
    }
    return $a;
}