Esempio n. 1
0
 function __construct($content, $title)
 {
     parent::__construct();
     define(GOOGLE_CODE_TRACKER_NOT_ACTIF, true);
     $this->render = new Table();
     $this->render->setWidth("100%");
     // Header
     if (defined('SITE_META_OPENGRAPH_IMAGE') && SITE_META_OPENGRAPH_IMAGE != "") {
         $logo = new Picture(SITE_META_OPENGRAPH_IMAGE);
     } else {
         $logo = new Picture("img/logo_128x400_" . $_SESSION['lang'] . ".png", 128, 400);
     }
     $logo->setTitle(__(SITE_NAME));
     $logo_link = new Link($this->getPage()->getBaseLanguageURL(), Link::TARGET_NONE, $logo);
     $img_obj = new Object($logo_link);
     $img_obj->add("<br/><br/>");
     $this->render->addRow($img_obj);
     $this->render->addRow();
     // Error message
     $small_img = new Picture("wsp/img/warning_16.png", 16, 16, 0, "absmiddle");
     $title_header = new Object($small_img, $title);
     $error_box = new Box($title_header, true, Box::STYLE_MAIN, Box::STYLE_MAIN, '', 'error_box', 700);
     $error_box->setContent($content);
     $this->render->addRow($error_box);
 }
 /**
  * @param string $dimensions in the format WxHxL ex: 2x3x4
  * @return Box
  */
 public function createBox($dimensions)
 {
     list($width, $height, $length) = explode('x', $dimensions);
     $box = new Box();
     $box->setWidth($width);
     $box->setHeight($height);
     $box->setLength($length);
     return $box;
 }
Esempio n. 3
0
function price_admin_page()
{
    if (isset($_POST['mfdvc'])) {
        $price = json_encode($_POST);
        $box = new Box();
        $box->add_price_option($price);
        see_price();
    } else {
        see_price();
    }
}
Esempio n. 4
0
 /**
  * Get packed weight
  * @return int weight in grams
  */
 public function getWeight()
 {
     if (!is_null($this->weight)) {
         return $this->weight;
     }
     $this->weight = $this->box->getEmptyWeight();
     $items = clone $this->items;
     foreach ($items as $item) {
         $this->weight += $item->getWeight();
     }
     return $this->weight;
 }
Esempio n. 5
0
 function draw()
 {
     global $__utime_start;
     global $__debug_array;
     debug($this, "Execution time (until debugWidget) :" . round(microtime_float() - $__utime_start, 3) . "s");
     $arr =& $__debug_array;
     $out .= "<table class=\"debug\"><tr><td class=\"debug_header\">Object</td><td class=\"debug_header\">Message</td></tr>";
     for ($i = 0; $i < count($arr); $i++) {
         $out .= "<tr><td class=\"debug_object\"><b>" . $arr[$i]["object"] . "</b></td><td class=\"debug_message\">" . $arr[$i]["message"] . "</td></tr>";
     }
     $out .= "</table>";
     $box = new Box("ooCommon NG Debug");
     $box->addWidget(html::write($out));
     return $box->draw();
 }
 /**
  * Show the member edit page
  *
  * @return string Returns the member edit page as HTML code.
  */
 public function boxEdit()
 {
     if ($Box = Box::get()->byID($this->request->param('ID'))) {
         $GLOBALS['BoxID'] = $Box->ID;
     }
     return $this->customise(new ArrayData(array("Title" => _t('AdminBoxEdit.TITLE', 'AdminBoxEdit.TITLE'), "Form" => $this->BoxEditForm(), "Box" => $Box)))->renderWith(array('BoxAdmin_boxedit', 'BoxAdmin', $this->stat('template_main'), $this->stat('template')));
 }
 public function doAdd(array $data)
 {
     //print_r($data, true); die();
     if ($Box = Box::get()->byID($data['BoxID'])) {
         $Box->Description = $data['Description'];
         // Update Description
         $Box->write();
         $Version = new BoxVersion();
         $Version->Version = $data['Version'];
         $Version->BoxID = $Box->ID;
         $Version->write();
         $Provider = new BoxProvider();
         $Provider->Name = 'virtualbox';
         $Provider->VersionID = $Version->ID;
         $Provider->ChecksumType = 'sha1';
         $this->saveInto($Provider);
         //$Provider->write();
         $Provider->Checksum = sha1_file($Provider->File()->getFullPath());
         $Provider->write();
     } else {
         $this->sessionMessage(_t('BoxAddVersionForm.INVALIDBOX', 'BoxAddVersionForm.INVALIDBOX'), 'bad');
         return $this->controller->redirectBack();
     }
     $this->controller->redirect('cloud/index');
 }
Esempio n. 8
0
 public function doEdit(array $data)
 {
     if ($Box = Box::get()->byID($data['ID'])) {
         $this->saveInto($Box);
         $Box->write();
     }
     $this->controller->redirect('boxadmin/boxes');
 }
Esempio n. 9
0
 /**
  * 实例化对像
  * 
  * @return class
  */
 public static function factory()
 {
     if (!isset(self::$_class)) {
         $className = __CLASS__;
         self::$_class = new $className();
     }
     return self::$_class;
 }
Esempio n. 10
0
 /**
  * Get volume utilisation of the packed box
  * @return float
  */
 public function getVolumeUtilisation()
 {
     $itemVolume = 0;
     /** @var Item $item */
     foreach (clone $this->items as $item) {
         $itemVolume += $item->getVolume();
     }
     return round($itemVolume / $this->box->getInnerVolume() * 100, 1);
 }
Esempio n. 11
0
 /**
  * Retrieves the HTML string.
  *
  * @return string
  */
 public function toHtml()
 {
     if (empty($this->top->right)) {
         $style = 'style="cursor:pointer;"';
         $onclick = sprintf('onclick="neat.toggle(\'%s\', \'%s\');"', $this->id, $this->overlay->id);
         $this->top->right = sprintf('<strong %s %s>X</strong>', $style, $onclick);
     }
     return $this->overlay . parent::toHtml();
 }
Esempio n. 12
0
 /**
  * Injects the layout/view to the controller.
  *
  * @param \Ilch\Layout\Base $layout
  * @param \Ilch\View        $view
  * @param \Ilch\Request     $request
  * @param \Ilch\Router      $router
  * @param \Ilch\Translator   $translator
  */
 public function __construct(\Ilch\Layout\Base $layout, \Ilch\View $view, \Ilch\Request $request, \Ilch\Router $router, \Ilch\Translator $translator)
 {
     parent::__construct($layout, $view, $request, $router, $translator);
     $this->db = Registry::get('db');
     if (!isset(Box::$staticBoxUniqid)) {
         Box::$staticBoxUniqid = 0;
     } else {
         Box::$staticBoxUniqid++;
     }
     $this->boxUniqid = Box::$staticBoxUniqid;
 }
Esempio n. 13
0
 public function doAdd(array $data)
 {
     if ($Box = Box::get()->filter(array("Title" => $data['Title']))->first()) {
         $this->addErrorMessage('Title', _t('BoxAddForm.TITLEEXISTS', 'BoxAddForm.TITLEEXISTS'), 'bad');
         $this->controller->redirectBack();
         return false;
     }
     $Box = Box::create();
     $this->saveInto($Box);
     $Box->write();
     $this->controller->redirect('boxadmin/boxes');
 }
Esempio n. 14
0
 /**
  * Generate new delivery dates and boxes for each date
  */
 public function actionCreateFutureDeliveryDatesAndBoxes()
 {
     $weeksInAdvance = SnapUtil::config('boxomatic/autoCreateDeliveryDates');
     $latestDate = DeliveryDate::getLastEnteredDate();
     if ($latestDate) {
         $latestDate = strtotime($latestDate->date);
     } else {
         $latestDate = time();
     }
     $targetDate = strtotime('+' . $weeksInAdvance . ' weeks');
     $BoxSizes = BoxSize::model()->findAll();
     while ($latestDate <= $targetDate) {
         //			$dateStr = date('j-n-Y',$latestDate);
         //			$parts = explode('-',$dateStr);
         //			mktime(0,0,0,$parts[1],$parts[0],$parts[2]);
         foreach (SnapUtil::config('boxomatic/deliveryDateLocations') as $day => $locationIds) {
             if (!empty($locationIds)) {
                 $latestDate = strtotime('next ' . $day, $latestDate);
                 //var_dump(date('l, d-m-Y',$latestDate));
                 //$latestDateStr=date('Y-m-d',$latestDate);
                 //$latestDate=strtotime($latestDateStr . ' +1 week');
                 $newDateStr = date('Y-m-d', $latestDate);
                 $DeliveryDate = new DeliveryDate();
                 $DeliveryDate->date = $newDateStr;
                 $DeliveryDate->Locations = $locationIds;
                 $DeliveryDate->save();
                 foreach ($BoxSizes as $BoxSize) {
                     $Box = new Box();
                     $Box->size_id = $BoxSize->id;
                     $Box->box_price = $BoxSize->box_size_price;
                     $Box->delivery_date_id = $DeliveryDate->id;
                     $Box->save();
                 }
                 echo '<p>Created new delivery_date: ' . $DeliveryDate->date . '</p>';
             }
         }
     }
     echo '<p><strong>Finished.</strong></p>';
     Yii::app()->end();
 }
Esempio n. 15
0
 public function Load()
 {
     parent::$PAGE_TITLE = __(HOME_PAGE_TITLE);
     // Welcome message
     $small_img = new Picture("img/logo_16x16.png", 16, 16, 0, Picture::ALIGN_ABSMIDDLE);
     $title_header = new Object($small_img, __(WELCOME));
     $welcome_box = new Box($title_header, true, Box::STYLE_SECOND, Box::STYLE_SECOND, "", "welcome_box", 600);
     $welcome_obj = new Object(__(WELCOME_MSG));
     list($strAdminLogin, $strAdminPasswd, $strAdminRights) = getWspUserRightsInfo("admin");
     $quickstart_obj = new Object(new Picture("img/quickstart_128.png", 64, 64), "<br/>", __(QUICKSTART));
     $quickstart_link = new Link("http://www.website-php.com/" . $this->getLanguage() . "/quick-start.html", Link::TARGET_BLANK, $quickstart_obj);
     $quickstart_box = new RoundBox(3, "quickstart_box", 120, 120);
     $quickstart_box->setValign(RoundBox::VALIGN_CENTER);
     $quickstart_box->setContent($quickstart_link);
     $tutorial_obj = new Object(new Picture("img/tutorials_128.png", 64, 64), "<br/>", __(TUTORIALS));
     $tutorial_link = new Link("http://www.website-php.com/" . $this->getLanguage() . "/tutorials.html", Link::TARGET_BLANK, $tutorial_obj);
     $tutorial_box = new RoundBox(3, "tutorial_box", 120, 120);
     $tutorial_box->setValign(RoundBox::VALIGN_CENTER);
     $tutorial_box->setContent($tutorial_link);
     $connect_obj = new Object(new Picture("img/wsp-admin/admin_128.png", 64, 64), "<br/>", __(CONNECT));
     $connect_link = new Link("wsp-admin/connect.html", Link::TARGET_BLANK, $connect_obj);
     $connect_box = new RoundBox(3, "connect_box", 120, 120);
     $connect_box->setValign(RoundBox::VALIGN_CENTER);
     $connect_box->setContent($connect_link);
     $icon_table = new Table();
     $icon_table->setDefaultAlign(RowTable::ALIGN_CENTER)->setDefaultValign(RowTable::VALIGN_TOP);
     $icon_row = $icon_table->addRowColumns($quickstart_box, "&nbsp;", $tutorial_box, "&nbsp;", $connect_box);
     $icon_row->setColumnWidth(5, 120);
     if ($strAdminLogin == "admin" && $strAdminPasswd == sha1("admin")) {
         $finalize = new Font(__(FINALIZE_INSTALL));
         $finalize->setFontColor("red");
         $finalize->setFontWeight(Font::FONT_WEIGHT_BOLD);
         $welcome_obj->add("<br/>", $finalize, "<br/>", __(CONNECT_DEFAULT_PASSWD), "<br/>");
     }
     $welcome_obj->add("<br/>", $icon_table);
     $welcome_box->setContent($welcome_obj);
     // Footer
     $this->render = new Template($welcome_box);
 }
Esempio n. 16
0
function loadBoxesFromFile($file)
{
    $handle = fopen($file, 'r');
    $boxes = [];
    if ($handle) {
        while (($line = fgets($handle)) !== false) {
            $boxes[] = Box::createFromString($line);
        }
        if (!feof($handle)) {
            throw new Exception("Error: unexpected fgets() fail\n");
        }
        fclose($handle);
    }
    return $boxes;
}
Esempio n. 17
0
 /**
  * Duplicate a Box and all its items
  * @return boolean 
  */
 public function duplicate()
 {
     $newBox = new Box();
     $newBox->attributes = $this->attributes;
     $newBox->box_id = null;
     $newBox->save();
     foreach ($this->BoxItems as $BoxItem) {
         $newBoxItem = new BoxItem();
         $newBoxItem->attributes = $BoxItem->attributes;
         $newBoxItem->box_item_id = null;
         $newBoxItem->box_id = $newBox->box_id;
         $newBoxItem->save();
     }
     return true;
 }
Esempio n. 18
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $dbox = Boxstatus::where('appname', '=', Config::get('jex.tracker_app'))->where('deliveryStatus', '=', Config::get('jayon.trans_status_mobile_delivered'))->get();
     if ($dbox) {
         foreach ($dbox as $dbx) {
             print 'box status : ' . $dbx->deliveryId . ' ' . $dbx->boxId . ' ' . $dbx->deliveryStatus . "\r\n";
             $box = Box::where('delivery_id', '=', $dbx->deliveryId)->where(function ($q) use($dbx) {
                 $q->where('box_id', '=', intval($dbx->boxId))->orWhere('box_id', '=', strval($dbx->boxId));
             })->first();
             if ($box) {
                 print 'box before : ' . $box->delivery_id . ' ' . $box->box_id . ' ' . $box->deliveryStatus . "\r\n";
                 $box->deliveryStatus = $dbx->deliveryStatus;
                 print 'box after : ' . $box->delivery_id . ' ' . $box->box_id . ' ' . $box->deliveryStatus . "\r\n";
                 $box->save();
             }
         }
     }
 }
Esempio n. 19
0
 function renderItems($items, $level = 0)
 {
     global $Controller;
     $r = '';
     $r .= '<ol class="' . ($level ? '' : 'list ') . 'bookitems bookitems_' . $level . '">';
     $i = 1;
     foreach ($items as $item) {
         if (!($o = $Controller->{$item['id']}(READ))) {
             continue;
         }
         $r .= '<li class="' . ($i++ % 2 ? 'odd' : 'even') . '">' . '<span class="fixed-width">' . $o->link() . '</span>' . Box::tools($o);
         if (isset($item['children'])) {
             $r .= self::renderItems($item['children'], $level + 1);
         }
         $r .= '</li>';
     }
     $r .= '</ol>';
     return $r;
 }
 public function test_getters()
 {
     /** === Test Data === */
     /** === Mocks === */
     $mConvert = $this->_mockFor(\Praxigento\Core\Lib\Tool\Convert::class);
     $mDate = $this->_mockFor(\Praxigento\Core\Tool\IDate::class);
     $mFormat = $this->_mockFor(\Praxigento\Core\Tool\IFormat::class);
     $mPeriod = $this->_mockFor(\Praxigento\Core\Tool\IPeriod::class);
     $mScheme = $this->_mockFor(\Praxigento\Bonus\Hybrid\Lib\Tool\IScheme::class);
     $mDownlineTree = $this->_mockFor(\Praxigento\Downline\Tool\ITree::class);
     /** === Test itself === */
     $obj = new Box($mConvert, $mDate, $mFormat, $mPeriod, $mScheme, $mDownlineTree);
     $this->assertInstanceOf(\Praxigento\Core\Lib\Tool\Convert::class, $obj->getConvert());
     $this->assertInstanceOf(\Praxigento\Core\Tool\IDate::class, $obj->getDate());
     $this->assertInstanceOf(\Praxigento\Core\Tool\IFormat::class, $obj->getFormat());
     $this->assertInstanceOf(\Praxigento\Core\Tool\IPeriod::class, $obj->getPeriod());
     $this->assertInstanceOf(\Praxigento\Bonus\Hybrid\Lib\Tool\IScheme::class, $obj->getScheme());
     $this->assertInstanceOf(\Praxigento\Downline\Tool\ITree::class, $obj->getDownlineTree());
 }
Esempio n. 21
0
 /**
  * @dataProvider getSizesAndSquares
  *
  * @param integer $width
  * @param integer $height
  * @param integer $square
  */
 public function testShouldCalculateSquare($width, $height, $square)
 {
     $box = new Box($width, $height);
     $this->assertEquals($square, $box->square());
 }
Esempio n. 22
0
 public function boxList($field, $val, $device_key, $obj = false)
 {
     $boxes = \Box::where($field, '=', $val)->get();
     $bx = array();
     if ($obj == true) {
         $boxes = $boxes->toArray();
         for ($n = 0; $n < count($boxes); $n++) {
             $ob = new \stdClass();
             foreach ($boxes[$n] as $k => $v) {
                 if ($k != '_id' && $k != 'id') {
                     $nk = $this->underscoreToCamelCase($k);
                 } else {
                     $nk = $k;
                 }
                 $ob->{$nk} = is_null($v) ? '' : $v;
             }
             //print_r($ob);
             $ob->extId = $ob->_id;
             unset($ob->_id);
             $ob->status = $this->lastBoxStatus($device_key, $ob->deliveryId, $ob->fulfillmentCode, $ob->boxId);
             $boxes[$n] = $ob;
         }
         return $boxes;
     } else {
         foreach ($boxes as $b) {
             $bx[] = $b->box_id;
         }
         if (count($bx) > 0) {
             return implode(',', $bx);
         } else {
             return '1';
         }
     }
 }
Esempio n. 23
0
{
    private $mainWidget;
    public $button1;
    public $button2;
    function __construct()
    {
        $mainWidget = new QWidget();
        parent::__construct(QBoxLayout::TopToBottom, $mainWidget);
        $this->mainWidget = $mainWidget;
        $this->button1 = new QPushButton("About Qt!");
        $this->button2 = new QPushButton("Quit");
        $this->addWidget($this->button1);
        $this->addWidget($this->button2);
    }
    function __destruct()
    {
        $this->button1 = 0;
        $this->button2 = 0;
        $this->mainWidget = 0;
    }
    function show()
    {
        $this->mainWidget->show();
    }
}
$app = new QApplication($argc, $argv);
$box = new Box();
$box->show();
QObject::connect($box->button1, SIGNAL("clicked()"), $app, SLOT("aboutQt()"));
QObject::connect($box->button2, SIGNAL("clicked()"), $app, SLOT("quit()"));
$app->exec();
Esempio n. 24
0
                                <td class="value"><strong><?php 
    echo SnapFormat::currency(BoxItem::dateTarget($SelectedDeliveryDate->id));
    ?>
</strong></td>
                                <td></td>
                            </tr>
                            <tr>
                                <td class="total" colspan="3">
                                    Box Retail:
                                </td>
                                <?php 
    $totalRetal = 0;
    foreach ($DeliveryDateBoxes as $DeliveryDateBoxMerged) {
        $dateBoxIds = explode(',', $DeliveryDateBoxMerged->box_ids);
        foreach ($dateBoxIds as $dateBoxId) {
            $DateBox = Box::model()->findByPk($dateBoxId);
            $retail = $value = $DateBox->retailPrice;
            $totalRetal += $retail;
            ?>
                                        <td class="value <?php 
            echo $retail > $DateBox->box_price ? 'red' : '';
            ?>
"><?php 
            echo SnapFormat::currency($retail);
            ?>
</td>
                                    <?php 
        }
        ?>
                                <?php 
    }
Esempio n. 25
0
 public function boxList($field, $val)
 {
     $boxes = \Box::where($field, '=', $val)->get();
     $bx = array();
     foreach ($boxes as $b) {
         $bx[] = $b->box_id;
     }
     if (count($bx) > 0) {
         return implode(',', $bx);
     } else {
         return '1';
     }
 }
Esempio n. 26
0
/**
    @param $end_marker<Marker> can be null if S2S search
    @return<Path2> a path from the start to the end or null if none is found
*/
function findPath($open, $end_stations, $end_marker)
{
    $debug = false;
    $debug_all = false;
    $WALKING_SPEED = 2 / 3600;
    $STATION_STOP_TIME = 30;
    $TRANSFER_TIME = 45;
    $RATIO = 0.75;
    $completed_time = -1;
    $completed_stops = -1;
    if ($debug) {
        echo "findPath<br/>";
    }
    global $markers;
    // create array of completed paths
    $completed = array();
    // there's a bug in PHP where passing an array by value that contains objects passes the objects by reference
    $new_open = array();
    foreach ($open as $path_array) {
        $new_array = array();
        $time = 0;
        foreach ($path_array as $path) {
            $new_array[] = $path->createCopy();
            $time = $path->time;
        }
        $new_open["{$time}"] = $new_array;
    }
    $one_path = findAPath($new_open, $end_stations, $end_marker);
    if ($one_path != null) {
        if ($debug) {
            echo "path by shortest distance: " . $one_path->toString() . "<br/>";
        }
        /*if (count($one_path->path) <= 2) {
              // this path does not even take the subway. no point searching for anything else.
              return $one_path;
          }*/
        $completed[] = $one_path;
        // set time
        $completed_time = $one_path->time;
        $completed_stops = count($one_path->path);
    }
    // create closed paths
    $closed = array();
    $restart = false;
    #$counter = 0;
    $multiple_paths = array();
    while (count($open) > 0) {
        #echo "loop: $counter<br/>";
        #$counter++;
        if (!is_array($open)) {
            return null;
        }
        if ($debug_all) {
            echo "open size = " . count($open) . "<br/>";
        }
        ksort($open);
        // look at the path at the front of OPEN, remove from list
        $keys = array_keys($open);
        $key = $keys[0];
        $multiple_paths = array_shift($open);
        if (is_array($multiple_paths)) {
            $path = array_shift($multiple_paths);
        } else {
            return null;
        }
        if (count($multiple_paths) > 0) {
            $open["{$key}"] = $multiple_paths;
        }
        if ($completed_time > 0 && $completed_time < $path->time) {
            if ($debug_all) {
                echo "path is too long ({$completed_time} < " . $new_path2->time . "). discard.<br/>";
            }
            continue;
        }
        $par = $completed_time * pow($completed_stops, 2);
        if ($completed_stops > 0 && $completed_time > 0) {
            $metric = pow(count($path->path), 2) * $path->time;
            #echo "metric = $metric | par = $par<br/>";
            if ($par / $metric < 0.8) {
                if ($debug_all) {
                    echo "path metric is too big (" . $par / $metric . "). discard.<br/>";
                }
                continue;
            }
        }
        $boundary_box = $path->bounding_box;
        #echo "box area = " . $boundary_box->getArea() . "<br/>";
        // print path
        if ($debug_all) {
            echo $path->toString();
        }
        // find degree of freedom for each station at the end of each path
        // DoF is defined as the number of outbound connections from the marker
        $last_marker = $path->getLastMarker();
        if ($debug_all) {
            $last_marker->printInfo();
        }
        // for some reason the last marker and the end marker are the same.
        // 4 E 28th St, New York, NY 10016 to 350 5th Ave, New York, NY 10118
        // add to path and continue
        if ($last_marker->id == $end_marker->id) {
            $completed[] = $path;
            continue;
        }
        //$box = new Box($last_marker->point, $end_marker->point);
        #echo "box area = " . $box->getArea() . "<br/>";
        #$stl_marker = $path->getSTLMarker();
        #echo $stl_marker->toString() . " looking at marker = [" . $last_marker->toString() . "]<br/>";
        $lines_array = $last_marker->getLines();
        /*if ($debug_all) {
              echo "lines_array<br/>\n";
              print_r($lines_array);
              echo "<br/>\n";
          }*/
        $DoF = getDegreeOfFreedom($lines_array);
        $connection_added = array();
        if ($DoF - 1 <= 1) {
            // station only has two connections
            // grab the next station
            $old_marker = $path->getSTLMarker();
            // loop through each connection and find the new marker
            #echo "connections = <br/>";
            foreach ($lines_array[0]->getConnections() as $connection) {
                #echo $connection->id . ": ";
                if ($connection->id != $old_marker->id) {
                    // new marker found, add to path
                    $next_marker = $markers[$connection->id];
                    //if ($debug) {
                    //    echo "next_marker: $next_marker->id<br/>";
                    //}
                    $original_dist = $last_marker->point->getDistanceMiles($end_marker->point);
                    $dist = $next_marker->point->getDistanceMiles($end_marker->point);
                    #echo "p2p distance = $dist ";
                    #echo "from " . $next_marker->toString() . "<br/>";
                    // calculate the box
                    if ($single_path_length < 3) {
                        $new_box = new Box($next_marker->point, $end_marker->point);
                    } else {
                        $new_box = null;
                    }
                    $single_path_length = $path->single_path_length;
                    if ($original_dist < $dist && $single_path_length > 2) {
                        if ($new_box->getArea() > $boundary_box->getArea()) {
                            // outside our scope, move to closed list
                            ##echo "spl: $single_path_length :: bounding box (". $next_marker->id .") is too big: " . $new_box->getArea() . ">" . $boundary_box->getArea() . ". will not add path...<br/>";
                            $closed[] = $path;
                            continue;
                        }
                    }
                    $single_path_length++;
                    if (in_array($next_marker, $path->visited)) {
                        if ($debug_all) {
                            echo "connection (" . $connection->id . ") is backtracking to " . $next_marker->toString() . ". ignoring.<br/>";
                        }
                        continue;
                    }
                    if (in_array($next_marker->id, $connection_added)) {
                        if ($debug_all) {
                            echo "[{$next_marker->id}] marker was already added. skipping.<br/>\n";
                        }
                        continue;
                    }
                    $new_path = new Path2($path, $next_marker, $lines_array[0], $connection->duration + $STATION_STOP_TIME, $connection->type, $new_box, $path->visited, $single_path_length);
                    $connection_added[] = $next_marker->id;
                    // check to see if the new station is one of the end stations. if so, then mark the path as completed and remove from OPEN
                    foreach ($end_stations as $station) {
                        /*
                            If the station marker is the next marker, then we know we're at one of the end points. We will definitely add this path, but we should also make one more check to see if the next possible marker is also an end station.
                        */
                        if ($station->marker == $next_marker) {
                            // grab the next set of markers from this marker and see if any of them are also end stations
                            $next_lines = $next_marker->lines;
                            foreach ($next_lines as $next_line) {
                                $next_connections = $next_line->connections;
                                foreach ($next_connections as $next_connection) {
                                    // check if each connection matches
                                    foreach ($end_stations as $station) {
                                        $connection_id = $next_connection->id;
                                        if ($connection_id == $station->marker->id) {
                                            // we found a marker that's valid
                                            // create a path
                                            $alternate_path = new Path2($new_path, $markers[$connection_id], $next_line, $next_connection->duration, $next_connection->type, $box, $new_path->visited, $single_path_length);
                                            // add the walking segment
                                            $alternate_path->addSegment(new Segment($alternate_path->getLastMarker(), $end_marker, null, $station->getDistance() / $WALKING_SPEED, "walking"), null);
                                            // verify path is valid
                                            if ($completed_time > 0 && $completed_time < $alternate_path->time) {
                                                // discarding because the time for this path is slower than one we already have
                                                if ($debug_all) {
                                                    echo "path ({$next_marker->id}) is too long ({$completed_time} < " . $alternate_path->time . "). discard.<br/>";
                                                }
                                                break;
                                            }
                                            // calculate par
                                            $par = $completed_time * pow($completed_stops, 2);
                                            if ($completed_stops > 0 && $completed_time > 0) {
                                                // if we have something to compare it to, then compare
                                                $metric = pow(count($path->path), 2) * $path->time;
                                                if ($par / $metric < $RATIO) {
                                                    if ($debug_all) {
                                                        echo "path metric ({$next_marker->id}) is too big (" . $par / $metric . "). discard.<br/>";
                                                    }
                                                    break;
                                                }
                                            }
                                            if ($debug) {
                                                echo "adding (" . $alternate_path->toString() . ") to COMPLETED<br/>";
                                            }
                                            // add the path to completed
                                            $completed[] = $alternate_path;
                                            if ($completed_time < 0 || $completed_time > $alternate_path->time) {
                                                $completed_time = $alternate_path->time;
                                                $completed_stops = count($alternate_path->path);
                                            }
                                            if ($debug_all) {
                                                echo "completed time = {$completed_time}<br/>";
                                                echo "completed stops = {$completed_stops}<br/>";
                                            }
                                            break;
                                        }
                                        // if ($connection_id
                                    }
                                    // foreach ($end_stations
                                }
                                // foreach ($next_connections
                            }
                            // foreach ($next_lines
                            // check to see if it is the end marker
                            if ($end_marker != $next_marker) {
                                // add end location marker
                                $new_path2 = new Path2($new_path, $end_marker, null, $station->getDistance() / $WALKING_SPEED, "walking", $box, $new_path->visited, $single_path_length);
                            } else {
                                // otherwise use the existing path
                                $new_path2 = $new_path;
                            }
                            if ($completed_time > 0 && $completed_time < $new_path2->time) {
                                // discarding because the time for this path is slower than one we already have
                                if ($debug_all) {
                                    echo "path ({$next_marker->id}) is too long ({$completed_time} < " . $new_path2->time . "). discard.<br/>";
                                }
                                continue;
                            }
                            // calculate par
                            $par = $completed_time * pow($completed_stops, 2);
                            if ($completed_stops > 0 && $completed_time > 0) {
                                // if we have something to compare it to, then compare
                                $metric = pow(count($path->path), 2) * $path->time;
                                if ($par / $metric < $RATIO) {
                                    if ($debug_all) {
                                        echo "path metric ({$next_marker->id}) is too big (" . $par / $metric . "). discard.<br/>";
                                    }
                                    continue;
                                }
                            }
                            // add path to COMPLETED and remove from OPEN
                            if ($debug) {
                                echo "adding (" . $new_path2->toString() . ") to COMPLETED<br/>";
                            }
                            $completed[] = $new_path2;
                            if ($completed_time < 0 || $completed_time > $new_path2->time) {
                                $completed_time = $new_path2->time;
                                $completed_stops = count($new_path2->path);
                            }
                            if ($debug_all) {
                                echo "completed time = {$completed_time}<br/>";
                                echo "completed stops = {$completed_stops}<br/>";
                            }
                            #$restart = true;
                            break;
                        }
                    }
                    // add path back to open
                    if (!$restart) {
                        #echo "adding path to OPEN<br/>";
                        $box = $new_path->bounding_box;
                        if (!is_null($box)) {
                            $area = $new_path->bounding_box->getArea();
                        } else {
                            $area = 0;
                        }
                        $multi_paths = $open["{$area}"];
                        if ($multi_paths == null) {
                            $multi_paths = array();
                        }
                        $add_path = true;
                        foreach ($multi_paths as $check_path) {
                            $check_box = $check_path->bounding_box;
                            if (!is_null($check_box)) {
                                if ($area > $check_box->getArea()) {
                                    echo "1 PATH bounding box ({$area}) is too big: " . $new_path->toString() . "<br/>";
                                    $add_path = false;
                                    break;
                                }
                            }
                        }
                        if ($add_path) {
                            $multi_paths[] = $new_path;
                            $open["{$area}"] = $multi_paths;
                        }
                    } else {
                        break;
                    }
                }
            }
            // foreach ($lines_array[0]
        } else {
            // more than one line so we need to determine whether the connection is outside the box
            // find connecting stations
            foreach ($lines_array as $line) {
                $connections = $line->getConnections();
                #echo "[" . $line->name . "] number of connections = " . count($connections) . "<br/>";
                // for each station
                foreach ($connections as $connection) {
                    $next_marker = $markers[$connection->id];
                    #echo "connection = " . $connection->id . "<br/>";
                    #echo "next_marker = " . $next_marker->toString() . "<br/>";
                    // if station is in the path
                    if (in_array($next_marker, $path->visited)) {
                        if ($debug_all) {
                            echo "connection (" . $connection->id . ") is backtracking to " . $next_marker->toString() . ". ignoring.<br/>";
                        }
                        continue;
                    }
                    $original_dist = $last_marker->point->getDistanceMiles($end_marker->point);
                    $dist = $next_marker->point->getDistanceMiles($end_marker->point);
                    #echo "p2p distance = $dist ";
                    #echo "from " . $next_marker->toString() . "<br/>";
                    // calculate the box
                    $new_box = new Box($next_marker->point, $end_marker->point);
                    if (!is_null($boundary_box)) {
                        if ($original_dist < $dist) {
                            if ($new_box->getArea() > $boundary_box->getArea()) {
                                // outside our scope, move to closed list
                                if ($debug_all) {
                                    echo "new bounding box (" . $next_marker->id . ") is too big: " . $new_box->getArea() . ">" . $boundary_box->getArea() . ". will not add path<br/>";
                                }
                                $closed[] = $path;
                                continue;
                            }
                        }
                    }
                    // if station is in new box area
                    if ((is_null($boundary_box) || $boundary_box->withinBox($next_marker)) && !in_array($next_marker->id, $connection_added)) {
                        // add marker to path array
                        $new_path = new Path2($path, $next_marker, $line, $connection->duration + $STATION_STOP_TIME + $TRANSFER_TIME, $connection->type, $new_box, $path->visited, 0);
                        foreach ($path->getLastSegment()->lines as $last_line) {
                            if ($line->name == $last_line->name) {
                                $new_path = new Path2($path, $next_marker, $line, $connection->duration + $STATION_STOP_TIME, $connection->type, $new_box, $path->visited, 0);
                                #echo "no transfer..." . $line->name . " | " . $new_path->toString() . "<br/>";
                                break;
                            }
                        }
                        if ($debug_all) {
                            echo "new_path: " . $new_path->toString() . "<br/>";
                        }
                        $connection_added[] = $next_marker->id;
                        // check to see if the new station is one of the end stations. if so, then mark the path as completed and remove from OPEN
                        foreach ($end_stations as $station) {
                            // if path has ending station
                            if ($station->marker == $next_marker) {
                                // grab the next set of markers from this marker and see if any of them are also end stations
                                $next_lines = $next_marker->lines;
                                foreach ($next_lines as $next_line) {
                                    $next_connections = $next_line->connections;
                                    foreach ($next_connections as $next_connection) {
                                        // check if each connection matches
                                        foreach ($end_stations as $station) {
                                            $connection_id = $next_connection->id;
                                            if ($connection_id == $station->marker->id) {
                                                // we found a marker that's valid
                                                // create a path
                                                $alternate_path = new Path2($new_path, $markers[$connection_id], $next_line, $next_connection->duration, $next_connection->type, $box, $new_path->visited, $single_path_length);
                                                // add the walking segment
                                                $alternate_path->addSegment(new Segment($alternate_path->getLastMarker(), $end_marker, null, $station->getDistance() / $WALKING_SPEED, "walking"), null);
                                                // verify path is valid
                                                if ($completed_time > 0 && $completed_time < $alternate_path->time) {
                                                    // discarding because the time for this path is slower than one we already have
                                                    if ($debug_all) {
                                                        echo "path ({$next_marker->id}) is too long ({$completed_time} < " . $alternate_path->time . "). discard.<br/>";
                                                    }
                                                    break;
                                                }
                                                // calculate par
                                                $par = $completed_time * pow($completed_stops, 2);
                                                if ($completed_stops > 0 && $completed_time > 0) {
                                                    // if we have something to compare it to, then compare
                                                    $metric = pow(count($path->path), 2) * $path->time;
                                                    if ($par / $metric < $RATIO) {
                                                        if ($debug_all) {
                                                            echo "path metric ({$next_marker->id}) is too big (" . $par / $metric . "). discard.<br/>";
                                                        }
                                                        break;
                                                    }
                                                }
                                                if ($debug) {
                                                    echo "adding (" . $alternate_path->toString() . ") to COMPLETED<br/>";
                                                }
                                                // add the path to completed
                                                $completed[] = $alternate_path;
                                                if ($completed_time < 0 || $completed_time > $alternate_path->time) {
                                                    $completed_time = $alternate_path->time;
                                                    $completed_stops = count($alternate_path->path);
                                                }
                                                if ($debug_all) {
                                                    echo "completed time = {$completed_time}<br/>";
                                                    echo "completed stops = {$completed_stops}<br/>";
                                                }
                                                break;
                                            }
                                            // if ($connection_id
                                        }
                                        // foreach ($end_stations
                                    }
                                    // foreach ($next_connections
                                }
                                // foreach ($next_lines
                                if ($end_marker != $next_marker) {
                                    // add end location marker
                                    $new_path2 = new Path2($new_path, $end_marker, null, $station->getDistance() / $WALKING_SPEED, "walking", null, $new_path->visited, 0);
                                    if ($debug_all) {
                                        echo "created new path:: " . $new_path2->toString() . "<br/>";
                                    }
                                } else {
                                    $new_path2 = $new_path;
                                }
                                if ($completed_time > 0 && $completed_time < $new_path2->time) {
                                    if ($debug_all) {
                                        echo "path ({$next_marker->id}) is too long ({$completed_time} < " . $new_path2->time . "). discard.<br/>";
                                    }
                                    continue;
                                }
                                $par = $completed_time * pow($completed_stops, 2);
                                if ($completed_stops > 0 && $completed_time > 0) {
                                    $metric = pow(count($path->path), 2) * $path->time;
                                    #echo "par/metric = " . $par/$metric . "<br/>";
                                    if ($par / $metric < $RATIO) {
                                        #echo "path metric is too big (" . $par/$metric . "). discard.<br/>";
                                        continue;
                                    }
                                }
                                // add path to COMPLETED and remove from OPEN
                                if ($debug) {
                                    echo "adding (" . $new_path2->toString() . ") to COMPLETED<br/>";
                                }
                                $completed[] = $new_path2;
                                if ($completed_time < 0 || $completed_time > $new_path2->time) {
                                    $completed_time = $new_path2->time;
                                    $completed_stops = count($new_path2->path);
                                }
                                if ($debug_all) {
                                    echo "completed time = {$completed_time}<br/>";
                                    echo "completed stops = {$completed_stops}<br/>";
                                }
                                #$restart = true;
                                break;
                            }
                        }
                        // foreach ($end_station
                        // add path back to open
                        if (!$restart) {
                            #echo "adding path to OPEN<br/>";
                            $new_box = $new_path->bounding_box;
                            $area = 0;
                            if (!is_null($new_box)) {
                                $area = $new_box->getArea();
                            }
                            $multi_paths = $open["{$area}"];
                            if ($multi_paths == null) {
                                $multi_paths = array();
                            }
                            $add_path = true;
                            foreach ($multi_paths as $check_path) {
                                $check_box = $check_path->bounding_box;
                                $check_area = 0;
                                if (!is_null($check_box)) {
                                    $check_area = $check_box->getArea();
                                }
                                if ($area >= $check_area && $area != 0) {
                                    if ($debug_all) {
                                        echo "2 PATH bounding box ({$area}) is too big: " . $new_path->toString() . "<br/>";
                                    }
                                    $add_path = false;
                                    break;
                                }
                            }
                            if ($add_path) {
                                $multi_paths[] = $new_path;
                                $open["{$area}"] = $multi_paths;
                            }
                        } else {
                            break;
                        }
                    } else {
                        if ($debug_all) {
                            echo "PATH to ({$next_marker->id}) is outside of bounding box or connection has already been added.<br/>";
                        }
                    }
                }
                // foreach ($connections
            }
        }
        // else
        if (count($open) == 0 && count($completed) == 0) {
            // we didn't find a path! expand our search
            $open = $closed;
        }
        $restart = false;
    }
    // while (count($open) > 0)
    // return path with the shortest time
    if ($debug) {
        echo "number of COMPLETED = " . count($completed) . "<br/>";
    }
    $x = 0;
    $path = array_shift($completed);
    if (count($completed) > 0) {
        foreach ($completed as $apath) {
            if ($path->time > $apath->time) {
                $path = $apath;
            } else {
                if ($path->time == $apath->time) {
                    if (count($path->path) > count($apath->path)) {
                        $path = $apath;
                    }
                }
            }
        }
    }
    if ($debug) {
        echo "displaying path -- " . $path->toString() . "<br/>";
    }
    return $path;
}
Esempio n. 27
0
 /**
  * Get the date target
  */
 static function dateTarget($dateId)
 {
     $Item = Box::model()->with('UserBoxes')->find(array('select' => 'SUM(quantity * box_price) as total', 'condition' => 'delivery_date_id = ' . $dateId . ''));
     return $Item ? $Item->total : 0;
 }
Esempio n. 28
0
/**
    @param $end_marker<Marker> can be null if S2S search
    @return<Path2> a path from the start to the end or null if none is found
*/
function findPath($open, $end_stations, $end_marker)
{
    $walking_speed = 2 / 3600;
    #echo "findPath<br/>";
    global $markers;
    // create array of completed paths
    $completed = array();
    // create closed paths
    $closed = array();
    $restart = false;
    //$boundary_box = $original_box;
    #$counter = 0;
    $completed_time = -1;
    $completed_stops = -1;
    $multiple_paths = array();
    while (count($open) > 0) {
        #echo "loop: $counter<br/>";
        #$counter++;
        ##echo "open size = " . count($open) . "<br/>";
        //if (count($completed) > 4) {
        //    break;
        //}
        ksort($open);
        // look at the path at the front of OPEN, remove from list
        $keys = array_keys($open);
        #echo "KEYS = ";
        #print_r($keys);
        #echo "<br/>";
        $multiple_paths = $open[$keys[0]];
        $path = array_shift($multiple_paths);
        if (count($multiple_paths) == 0) {
            unset($open[$keys[0]]);
            if (count($open) > 0) {
                reset($open);
            } else {
                $open = array();
            }
        } else {
            $open[$keys[0]] = $multiple_paths;
        }
        if ($completed_time > 0 && $completed_time < $path->time) {
            #echo "path is too long ($completed_time < " . $new_path2->time . "). discard.<br/>";
            continue;
        }
        $par = $completed_time * pow($completed_stops, 2);
        if ($completed_stops > 0 && $completed_time > 0) {
            $metric = pow(count($path->path), 2) * $path->time;
            #echo "metric = $metric | par = $par<br/>";
            if ($par / $metric < 0.8) {
                #echo "path metric is too big (" . $par/$metric . "). discard.<br/>";
                continue;
            }
        }
        $boundary_box = $path->bounding_box;
        #echo "box area = " . $boundary_box->getArea() . "<br/>";
        #echo "open size (after shift) = " . count($open) . "<br/>";
        // print path
        ##echo $path->toString();
        // find degree of freedom for each station at the end of each path
        // DoF is defined as the number of outbound connections from the marker
        $last_marker = $path->getLastMarker();
        $box = new Box($last_marker->point, $end_marker->point);
        #$dist = $last_marker->point->getDistanceMiles($end_marker->point);
        #echo "p2p distance = $dist ";
        #echo "from".$last_marker->toString()."<br/>";
        #echo "box area = " . $box->getArea() . "<br/>";
        #$stl_marker = $path->getSTLMarker();
        #echo $stl_marker->toString() . " looking at marker = [" . $last_marker->toString() . "]<br/>";
        $lines_array = $last_marker->getLines();
        $DoF = getDegreeOfFreedom($lines_array);
        $connection_added = array();
        if ($DoF - 1 <= 1) {
            // station only has two connections
            // grab the next station
            $old_marker = $path->getSTLMarker();
            // loop through each connection and find the new marker
            #echo "connections = <br/>";
            foreach ($lines_array[0]->getConnections() as $connection) {
                #echo $connection->id . ": ";
                if ($connection->id != $old_marker->id) {
                    // new marker found, add to path
                    $next_marker = $markers[$connection->id];
                    $original_dist = $last_marker->point->getDistanceMiles($end_marker->point);
                    $dist = $next_marker->point->getDistanceMiles($end_marker->point);
                    #echo "p2p distance = $dist ";
                    #echo "from " . $next_marker->toString() . "<br/>";
                    // calculate the box
                    $new_box = new Box($next_marker->point, $end_marker->point);
                    if ($original_dist < $dist) {
                        if ($new_box->getArea() > $box->getArea()) {
                            // outside our scope, move to closed list
                            #echo "bounding box (". $next_marker->id .") is too big: " . $new_box->getArea() . ">" . $box->getArea() . ". will not add path<br/>";
                            $closed[] = $path;
                            continue;
                        }
                    }
                    if (in_array($next_marker, $path->visited)) {
                        #echo "connection (" . $connection->id . ") is backtracking to " . $next_marker->toString() .". ignoring.<br/>";
                        continue;
                    }
                    if (in_array($next_marker->id, $connection_added)) {
                        #echo "[$next_marker->id] marker was already added. skipping.<br/>\n";
                        continue;
                    }
                    $new_path = new Path2($path, $next_marker, $lines_array[0], $connection->duration, $connection->type, $new_box, $path->visited);
                    $connection_added[] = $next_marker->id;
                    // check to see if the new station is one of the end stations. if so, then mark the path as completed and remove from OPEN
                    foreach ($end_stations as $station) {
                        if ($station->marker == $next_marker) {
                            if ($end_marker != null) {
                                // add end location marker
                                $new_path2 = new Path2($new_path, $end_marker, null, $station->getDistance() / $walking_speed, "walking", $box, $new_path->visited);
                                #$new_path->addSegment(new Segment($next_marker, $end_marker, null, $station->getDistance()/$walking_speed, "walking"), $box);
                            }
                            if ($completed_time > 0 && $completed_time < $new_path2->time) {
                                #echo "path is too long ($completed_time < " . $new_path2->time . "). discard.<br/>";
                                continue;
                            }
                            $par = $completed_time * pow($completed_stops, 2);
                            if ($completed_stops > 0 && $completed_time > 0) {
                                $metric = pow(count($path->path), 2) * $path->time;
                                #echo "par/metric = " . $par/$metric . "<br/>";
                                if ($par / $metric < 0.75) {
                                    #echo "path metric is too big (" . $par/$metric . "). discard.<br/>";
                                    continue;
                                }
                            }
                            // add path to COMPLETED and remove from OPEN
                            #echo "adding (" . $new_path2->toString() . ") to COMPLETED<br/>";
                            $completed[] = $new_path2;
                            if ($completed_time < 0 || $completed_time > $new_path2->time) {
                                $completed_time = $new_path2->time;
                                $completed_stops = count($new_path2->path);
                            }
                            #echo "completed time = $completed_time<br/>";
                            #echo "completed stops = $completed_stops<br/>";
                            #$restart = true;
                            break;
                        }
                    }
                    // add path back to open
                    if (!$restart) {
                        #echo "adding path to OPEN<br/>";
                        $area = $new_path->bounding_box->getArea();
                        $multi_paths = $open["{$area}"];
                        if ($multi_paths == null) {
                            $multi_paths = array();
                        }
                        $add_path = true;
                        foreach ($multi_paths as $check_path) {
                            if ($new_path->bounding_box->getArea() > $check_path->bounding_box->getArea()) {
                                #echo "PATH bounding box is too big.<br/>";
                                $add_path = false;
                                break;
                            }
                        }
                        if ($add_path) {
                            //$key = $new_path->bounding_box->getArea();
                            $multi_paths[] = $new_path;
                            //ksort($multi_paths);
                            $area = $new_path->bounding_box->getArea();
                            #echo "adding $multi_paths<br/>";
                            $open["{$area}"] = $multi_paths;
                        }
                    } else {
                        break;
                    }
                }
            }
            // foreach ($lines_array[0]
            #echo "OOPEN size = " . count($open) . "<br/>";
        } else {
            // more than one line so we need to determine whether the connection is outside the box
            // find connecting stations
            foreach ($lines_array as $line) {
                $connections = $line->getConnections();
                #echo "[" . $line->name . "] number of connections = " . count($connections) . "<br/>";
                // for each station
                foreach ($connections as $connection) {
                    $next_marker = $markers[$connection->id];
                    // if station is in the path
                    if (in_array($next_marker, $path->visited)) {
                        #echo "connection (" . $connection->id . ") is backtracking to " . $next_marker->toString() .". ignoring.<br/>";
                        continue;
                    }
                    $original_dist = $last_marker->point->getDistanceMiles($end_marker->point);
                    $dist = $next_marker->point->getDistanceMiles($end_marker->point);
                    #echo "p2p distance = $dist ";
                    #echo "from " . $next_marker->toString() . "<br/>";
                    // calculate the box
                    $new_box = new Box($next_marker->point, $end_marker->point);
                    if ($original_dist < $dist) {
                        if ($new_box->getArea() > $box->getArea()) {
                            // outside our scope, move to closed list
                            #echo "new bounding box (". $next_marker->id .") is too big: " . $new_box->getArea() . ">" . $box->getArea() . ". will not add path<br/>";
                            $closed[] = $path;
                            continue;
                        }
                    }
                    // if station is in new box area
                    if ($box->withinBox($next_marker) && !in_array($next_marker->id, $connection_added)) {
                        // add marker to path array
                        $new_path = new Path2($path, $next_marker, $line, $connection->duration, $connection->type, $new_box, $path->visited);
                        $connection_added[] = $next_marker->id;
                        // check to see if the new station is one of the end stations. if so, then mark the path as completed and remove from OPEN
                        foreach ($end_stations as $station) {
                            // if path has ending station
                            if ($station->marker == $next_marker) {
                                if ($end_marker != null) {
                                    // add end location marker
                                    $new_path2 = new Path2($new_path, $end_marker, null, $station->getDistance() / $walking_speed, "walking", $box, $new_path->visited);
                                    //$new_path->addSegment(new Segment($next_marker, $end_marker, null, $station->getDistance()/$walking_speed, "walking"), $box);
                                }
                                if ($completed_time > 0 && $completed_time < $new_path2->time) {
                                    #echo "path is too long ($completed_time < " . $new_path2->time . "). discard.<br/>";
                                    continue;
                                }
                                $par = $completed_time * pow($completed_stops, 2);
                                if ($completed_stops > 0 && $completed_time > 0) {
                                    $metric = pow(count($path->path), 2) * $path->time;
                                    #echo "par/metric = " . $par/$metric . "<br/>";
                                    if ($par / $metric < 0.75) {
                                        #echo "path metric is too big (" . $par/$metric . "). discard.<br/>";
                                        continue;
                                    }
                                }
                                // add path to COMPLETED and remove from OPEN
                                ##echo "adding (" . $new_path2->toString() . ") to COMPLETED<br/>";
                                $completed[] = $new_path2;
                                if ($completed_time < 0 || $completed_time > $new_path2->time) {
                                    $completed_time = $new_path2->time;
                                    $completed_stops = count($new_path2->path);
                                }
                                #echo "completed time = $completed_time<br/>";
                                #echo "completed stops = $completed_stops<br/>";
                                #$restart = true;
                                break;
                            }
                        }
                        // foreach ($end_station
                        // add path back to open
                        if (!$restart) {
                            #echo "adding path to OPEN<br/>";
                            $area = $new_path->bounding_box->getArea();
                            $multi_paths = $open["{$area}"];
                            if ($multi_paths == null) {
                                $multi_paths = array();
                            }
                            $add_path = true;
                            foreach ($multi_paths as $check_path) {
                                if ($new_path->bounding_box->getArea() > $check_path->bounding_box->getArea()) {
                                    #echo "PATH bounding box is too big.<br/>";
                                    $add_path = false;
                                    break;
                                }
                            }
                            if ($add_path) {
                                //$key = $new_path->bounding_box->getArea();
                                $multi_paths[] = $new_path;
                                //ksort($multi_paths);
                                $area = $new_path->bounding_box->getArea();
                                #echo "adding $multi_paths<br/>";
                                $open["{$area}"] = $multi_paths;
                            }
                        } else {
                            break;
                        }
                    } else {
                        #echo "PATH is outside of bounding box or connection has already been added.<br/>";
                    }
                }
                // foreach ($connections
            }
            $boundary_box = $box;
        }
        // else
        if (count($open) == 0 && count($completed) == 0) {
            // we didn't find a path! expand our search
            $open = $closed;
        }
        $restart = false;
    }
    // while (count($open) > 0)
    // return path with the shortest time
    ##echo "number of COMPLETED = " . count($completed) . "<br/>";
    $x = 0;
    $path = array_shift($completed);
    if (count($completed) > 0) {
        foreach ($completed as $apath) {
            if ($path->time > $apath->time) {
                $path = $apath;
            } else {
                if ($path->time == $apath->time) {
                    if (count($path->path) > count($apath->path)) {
                        $path = $apath;
                    }
                }
            }
        }
    }
    echo $path->toString() . "<br/>";
    return $path;
}
Esempio n. 29
0
 /**
  * Public constructor
  *
  * @param  int   $spacing The Spacing of the box
  * @param  int   $border  Border size
  * @access public
  */
 function HBox($spacing = 0, $border = 0)
 {
     $this->setBorder($border);
     $this->setName('hbox' . rand(1, 100));
     parent::init();
 }
Esempio n. 30
0
<?php

use kahlan\Matcher;
class NoNamespace
{
    public function hello()
    {
        return "Hello World!";
    }
}
function test()
{
    return "It's a test";
}
if (true) {
    echo "Hello World!";
}
Matcher::register('toBe', 'kahlan\\matcher\\ToBe');
Box::share('kahlan.suite', function () {
    return new Suite();
});
?>

Outside PHP Tags

<?php 
for ($i = 0; $i < 10; $i++) {
    echo "Success";
}