Beispiel #1
0
function inspect_data($path, $depth)
{
    $data = file_get_contents($path);
    //, FILE_BINARY);
    $map = clb_blob_dec($data);
    qpre(pfind_shallow($map, $depth));
}
Beispiel #2
0
function pbuild_walk_links($ptypes, &$p2p_links, $stops_xref = FALSE, $meters = 400)
{
    global $wpdb;
    if (!is_array($ptypes)) {
        $ptypes = array($ptypes);
    }
    $toll_lat = $meters / METERS_PER_DEGREE;
    //$toll_lat is degrees equivalent of $meters in meters from the center
    $count = 0;
    //just count how many connections we are making
    $pos = array_search('plat', $ptypes);
    //dont include platforms in interchanged (we convert stations to platforms later)
    if (is_int($pos)) {
        unset($ptypes[$pos]);
    }
    $query = 'SELECT ' . RF_NODES_SELECT . ' FROM ' . RF_NODES_FROM . ' WHERE ' . RF_NODES_TYPE . ' IN ' . clb_join($ptypes, TRUE) . ' ORDER BY lat';
    $places = $wpdb->get_results($query, ARRAY_A);
    if (is_array($places)) {
        $lats = clb_column($places, 'lat');
        $lngs = clb_column($places, 'lng');
        $max = count($places);
        array_multisort($lats, SORT_ASC, $lngs, SORT_ASC, $places);
        foreach ($lats as $idx => $lat1) {
            $lng1 = $lngs[$idx];
            //allow larger degree difference in longitude because they represents fewer meters
            //also do it for each different lat
            $toll_lng = $toll_lat / cos($lat1);
            $scan = $idx + 1;
            //start one higher in the selection on each pass, as previous points already compared
            while ($scan < $max) {
                $lat2 = $lats[$scan];
                if (abs($lat2 - $lat1) > $toll_lat) {
                    break;
                }
                //all remaining latitudes will be too far away
                $lng2 = $lngs[$scan];
                if (abs($lng2 - $lng1) <= $toll_lng) {
                    //slightly extravegant, double check distance as a circle and not just a square.
                    $dist = pline_surface_dist($lat1, $lng1, $lat2, $lng2);
                    if ($dist < $meters) {
                        //nodes are within spitting distance but check if they are already connected
                        //but first check if the nodes have platforms
                        $pnum = clb_val(FALSE, $places, $idx, RF_NODES_KEY);
                        if ($stops_xref && !isset($stops_xref['stops'][$pnum])) {
                            continue;
                        }
                        //if no routes using this stop no need to include the interchange to it
                        $nodes1 = isset($p2p_links['stat2plat'][$pnum]) ? $p2p_links['stat2plat'][$pnum] : array($pnum);
                        $pnum = clb_val(FALSE, $places, $scan, RF_NODES_KEY);
                        if ($stops_xref && !isset($stops_xref['stops'][$pnum])) {
                            continue;
                        }
                        //if no routes using this stop no need to include the interchange to it
                        $nodes2 = isset($p2p_links['stat2plat'][$pnum]) ? $p2p_links['stat2plat'][$pnum] : array($pnum);
                        //normally there will only be one element in each array but if one or both has platforms we need to work the permutations
                        foreach ($nodes1 as $pnum1) {
                            foreach ($nodes2 as $pnum2) {
                                $txt = '';
                                $query = 'SELECT ' . RF_NODES_SELECT . ' FROM ' . RF_NODES_FROM . ' WHERE ' . RF_NODES_KEY . ' IN ' . clb_join(array($pnum1, $pnum2), TRUE);
                                $ends = $wpdb->get_results($query, ARRAY_A);
                                if (pbuild_make_link($p2p_links, $ends, $dist)) {
                                    $count++;
                                    $txt = '';
                                    if (is_array($ends)) {
                                        $peep = reset($ends);
                                        $txt .= $peep[RF_NODES_KEY] . ' / ' . $peep[RF_NODES_TYPE] . ' / ' . $peep[RF_NODES_NAME] . ', ';
                                        $p1 = $peep[RF_LINKS_TYPE];
                                        $peep = next($ends);
                                        $txt .= $peep[RF_NODES_KEY] . ' / ' . $peep[RF_NODES_TYPE] . ' / ' . $peep[RF_NODES_NAME] . ', ';
                                        if ($p1 == $peep[RF_LINKS_TYPE] && $p1 != 'rail') {
                                            $txt = '**** non rail ' . $txt;
                                        }
                                    }
                                    qpre(__LINE__, $count, $dist, $txt);
                                }
                            }
                        }
                        //producting of end nodes
                    }
                }
                $scan++;
            }
        }
    }
    //now ensure walking links between platforms at same station
    $query = 'SELECT ' . RF_NODES_SELECT . ' FROM ' . RF_NODES_FROM . ' WHERE ' . RF_NODES_TYPE . ' IN ' . clb_join(array('plat'), TRUE) . ' ORDER BY ' . RF_NODES_DESC;
    $places = $wpdb->get_results($query, ARRAY_A);
    if (clb_count($places)) {
        //group records by station
        $list = array();
        foreach ($places as $rec) {
            $list[$rec[RF_NODES_DESC]][] = $rec;
        }
        //get list of stations so we can access details
        $query = 'SELECT ' . RF_NODES_SELECT . ' FROM ' . RF_NODES_FROM . ' WHERE ' . RF_NODES_KEY . ' IN ' . clb_join(array_keys($list), TRUE);
        $places = $wpdb->get_results($query, ARRAY_A);
        $places = clb_rekey($places, RF_NODES_KEY);
        foreach ($list as $station => $plats) {
            if (clb_count($plats) > 1) {
                //check each platform has the name of its station in its name field
                $name = clb_val('', $places, $station, RF_NODES_NAME);
                $query = 'UPDATE ' . RF_NODES_FROM . ' SET ' . RF_NODES_NAME . '=' . clb_escape($name) . ' WHERE ' . RF_LINKS_KEY . '=';
                if ($name) {
                    foreach ($plats as $rec) {
                        if ($rec[RF_NODES_NAME] != $name) {
                            $wpdb->query($query . clb_escape($rec[RF_NODES_KEY]));
                        }
                    }
                }
                //permute platform connections
                $count = count($plats);
                for ($x = 0; $x < $count - 1; $x++) {
                    for ($y = $x + 1; $y < $count; $y++) {
                        pbuild_make_link($p2p_links, array($plats[$x], $plats[$y]));
                    }
                }
            }
        }
    }
    qlog(__LINE__, $count);
}
Beispiel #3
0
 }
 $stoplist = array();
 $details = $short_paths[$best_pos];
 $first = reset($details);
 //first node has total dist and changes count
 $node1 = clb_val(FALSE, $first, 'node');
 //could be a platform but that is OK, lets us orient first segment
 //qlog(__LINE__, $node1, $pnum2, count($short_paths), count($details));
 $stop_pnum = isset($p2p_links['plat2stat'][$node1]) ? $p2p_links['plat2stat'][$node1] : $node1;
 //0=pnum, 1=dist from last station to this one
 $stoplist['pnum'][] = $stop_pnum;
 $stoplist['dist'][] = 0;
 //loop to build stop list with real stations not platforms and with distances
 foreach ($details as $linkpnum => $info) {
     if (!isset($p2p_links['links'][$linkpnum])) {
         qpre('flatten - link record not found', $linkpnum, $pnum1, $pnum2);
         break;
     } else {
         parse_str($p2p_links['links'][$linkpnum], $linkrec);
         //get link rec by linkpnum
         $ptype = clb_val(0, $linkrec, 'ptype');
         $dist = 0;
         if ($ptype != 'walk') {
             $dist = clb_val(0, $linkrec, 'dist');
         }
         $next = isset($linkrec['end1']) && $node1 == $linkrec['end1'] ? $linkrec['end2'] : $linkrec['end1'];
         $stop_pnum = isset($p2p_links['plat2stat'][$next]) ? $p2p_links['plat2stat'][$next] : $next;
         $stoplist['pnum'][] = $stop_pnum;
         $stoplist['dist'][] = $dist;
         $node1 = $next;
     }
        //need different p2p files for different combinations of modes
        $index = clb_blob_dec($data);
        ksort($index);
        qpre($index);
}
if (IS_CLI) {
    db_close();
    exit;
} else {
    if ($path) {
        clb_timing(__LINE__);
        $data = file_get_contents($path, FILE_BINARY);
        clb_timing('load');
        $map = clb_blob_dec($data);
        qpre(clb_timing('decode'), 'count', count($map, 1));
        qpre('file content length/array', $path, strlen($data), $map);
    }
}
db_close();
$base = clb_make_url() . '?m=';
echo clb_tag('p', '', clb_tag('a', 'near', '', array('href' => $base . 'near')));
echo clb_tag('p', '', clb_tag('a', 'raw', '', array('href' => $base . 'raw')));
echo clb_tag('p', '', clb_tag('a', 'stops', '', array('href' => $base . 'stops')));
echo clb_tag('p', '', clb_tag('a', 'links', '', array('href' => $base . 'links')));
echo clb_tag('p', '', clb_tag('a', 'p2p', '', array('href' => $base . 'p2p')));
echo clb_tag('p', '', clb_tag('a', 'interchange', '', array('href' => $base . 'interchange')));
echo clb_tag('p', '', clb_tag('a', 'check_raw_ends', '', array('href' => $base . '7')));
echo clb_tag('p', '', clb_tag('a', 'hardcoded test case', '', array('href' => $base . '8')));
echo clb_tag('p', '', clb_tag('a', 'audit of tyube stops', '', array('href' => $base . '9')));
echo clb_tag('p', '', clb_tag('a', 'hardcoded tests for specific short paths', '', array('href' => $base . '10')));
echo clb_tag('p', '', clb_tag('a', 'arrays connecting nodes to raw segs', '', array('href' => $base . '11')));