示例#1
0
 public function __construct($object, $adjacentNodesCallback, $realCostCallback, $estimatedCostCallback)
 {
     parent::__construct();
     $this->object = $object;
     $this->adjacentNodesCallback = $adjacentNodesCallback;
     $this->realCostCallback = $realCostCallback;
     $this->estimatedCostCallback = $estimatedCostCallback;
 }
示例#2
0
 /**
  * @param Jose $jose
  * @param string $key
  * @param string|null $algorithm
  * @return string
  * @throws \InvalidArgumentException
  */
 public function encode(Jose $jose, $key, $algorithm = null)
 {
     $algorithm = $algorithm ? $algorithm : $this->getDefaultAlgorithm();
     if (false == Algorithm::isValid($algorithm)) {
         throw new \InvalidArgumentException(sprintf("Invalid algorithm '%s'", $algorithm));
     }
     $jose->headerSet(JwsHeader::ALGORITHM, $algorithm);
     $signing_input = $jose->getSigningInput();
     $signature = $this->sign($signing_input, $key, $algorithm);
     $signatureB64 = UrlSafeB64Encoder::encode($signature);
     return $signing_input . '.' . $signatureB64;
 }
示例#3
0
 /**
  * @param $person1 Person
  * @param $person2 Person
  * @return Person
  */
 public static function crossover($person1, $person2)
 {
     $child = new Person();
     if (Algorithm::hasMutation()) {
         $child->setEyesColor(new EyesColor(EyesColor::MARK_BLUE));
         $child->setHairColor(new HairColor(HairColor::MARK_BLONDE));
         $child->setSkinColor(new SkinColor(0));
         $child->setIsMutant(true);
     } else {
         $child->setEyesColor(Algorithm::getDominant($person1->getEyesColor(), $person2->getEyesColor()));
         $child->setHairColor(Algorithm::getDominant($person1->getHairColor(), $person2->getHairColor()));
         $child->setSkinColor(new SkinColor(floatval(($person1->getSkinColor()->getValue() + $person2->getSkinColor()->getValue()) / 2.0)));
     }
     $child->setParents([$person1->getId(), $person2->getId()]);
     return $child;
 }
 private function algorithm()
 {
     return Algorithm::create($this->algorithmName);
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Eloquent::unguard();
     $algorithmsXmls = File::allFiles(public_path() . '/algorithms');
     foreach ($algorithmsXmls as $algorithmsXml) {
         $dom = new DomDocument();
         $dom->load($algorithmsXml);
         $root = $dom->documentElement;
         $modality = Modality::whereName($root->getAttribute('modality'))->first();
         if (empty($modality)) {
             throw new Exception("Could not find modality! ({$algorithmsXml})");
         }
         $protocolName = $root->getAttribute('protocol');
         $protocol = Protocol::whereName($protocolName)->whereModalityId($modality->Id)->first();
         if (empty($protocol)) {
             \Log::warning("Could not find protocol! ({$algorithmsXml})");
             continue;
         }
         $arguments = [];
         $parameters = [];
         $description = "";
         foreach ($root->childNodes as $node) {
             if (get_class($node) == 'DOMText') {
                 continue;
             }
             switch ($node->nodeName) {
                 case 'arguments':
                     foreach ($node->childNodes as $argument) {
                         if (get_class($argument) == 'DOMText') {
                             continue;
                         }
                         $arguments[] = ['Name' => $argument->getAttribute('name')];
                     }
                     break;
                 case 'parameters':
                     foreach ($node->childNodes as $parameter) {
                         if (get_class($parameter) == 'DOMText') {
                             continue;
                         }
                         $parameters[] = ['Name' => $parameter->getAttribute('name'), 'Type' => $parameter->getAttribute('type'), 'Value' => $parameter->hasAttribute('value') ? $parameter->getAttribute('value') : null];
                     }
                     break;
                 case 'description':
                     $description = $node->textContent;
                     break;
                 default:
                     throw new Exception("Unrecognized entry in algorithm XML - {$node->nodeName}! ({$algorithmsXml})");
             }
         }
         $algorithm = new Algorithm();
         $algorithm->content = $description;
         $resultName = $root->getAttribute('result');
         $resultType = $root->getAttribute('type');
         $result = Parameter::whereName($resultName)->first();
         if (empty($result)) {
             $result = Parameter::create(['Name' => $resultName, 'Type' => $resultType]);
         }
         $algorithm->result()->associate($result);
         $algorithm->protocol()->associate($protocol);
         $algorithm->save();
         foreach ($arguments as $argument) {
             $algorithm->arguments()->attach(Argument::create($argument));
         }
         foreach ($parameters as $parameter) {
             $algorithm->attribute($parameter);
         }
     }
 }
{
    public function operation1() : string
    {
        return "ClassA::operation1";
    }
    public function operation2() : string
    {
        return "ClassA::operation2";
    }
}
class ClassB implements IPrimitives
{
    public function operation1() : string
    {
        return "ClassB::operation1";
    }
    public function operation2() : string
    {
        return "ClassB::operation2";
    }
}
class Algorithm
{
    public function templateMethod(IPrimitives $a)
    {
        echo $a->operation1(), " ", $a->operation2(), "\n";
    }
}
$m = new Algorithm();
$m->templateMethod(new ClassA());
$m->templateMethod(new ClassB());
示例#7
0
文件: AuthTest.php 项目: firehed/auth
 private function getKeyContainer() : KeyContainer
 {
     $kc = new KeyContainer();
     $kc->addKey(1, Algorithm::HMAC_SHA_256(), new Secret('top secret'));
     return $kc;
 }
示例#8
0
        ?>
</a>
                    </td>
                    <td>
                        <?php 
        echo $person->getIsMutant() ? 'Yes' : 'No';
        ?>
                    </td>
                </tr>
            <?php 
    }
    ?>
        </table>
    </section>
    <?php 
    $population = Algorithm::evolve($population, $target, $generationLevel);
    $generationLevel++;
    $solution = $population->getFittest($target);
}
?>


<section class="target">
<div>
    <h2>Max Populations: <?php 
echo $stopOnLevel;
?>
</h2>
</div>
<h1>Target</h1>
<table>
示例#9
0
 public function testSetValue()
 {
     $newValue = 'NewValue';
     $this->parameter->setValue($newValue);
     $this->assertSame($newValue, $this->parameter->getValue());
 }
 private function algorithm()
 {
     return Algorithm::create($this->parameter('algorithm'));
 }
示例#11
0
<?php

/**
 * Test suite for the linebreak
 */
$arr = [[28.06279, -80.62303199999999], [28.06397, -80.62299299999999], [28.063987, -80.62205], [28.06395, -80.62139999999999], [28.063928, -80.619944], [28.063926, -80.61993200000001], [28.063086, -80.61994900000001], [28.06307, -80.62033099999999], [28.062929, -80.62052199999999], [28.06287, -80.62114699999999], [28.06356, -80.62114], [28.06356, -80.62114], [28.063841, -80.621132], [28.063841, -80.619934], [28.06406, -80.61992600000001], [28.06408, -80.62103], [28.0640799, -80.62103999999999], [28.0640799, -80.62129400000001], [28.07075, -80.621213], [28.07197, -80.621224], [28.07498, -80.62129], [28.07498, -80.62197], [28.07649, -80.62197], [28.07649, -80.62159], [28.07495, -80.62139999999999], [28.07231, -80.62135000000001], [28.07185, -80.621335], [28.0695, -80.62135000000001], [28.06201, -80.62145], [28.061918, -80.62202000000001], [28.061884, -80.62215], [28.06192, -80.62233000000001], [28.06198, -80.62284], [28.06204, -80.623036], [28.06279, -80.62303199999999]];
$maxDist = 100;
//echo '<pre>';
//$significantPoints = Algorithm::significantTravelPoints($arr, $maxDist, true);
//$arrSize = count($significantPoints[1]);
//
//for ($i = 0; $i < $arrSize; $i++) {
//
//    print '[' . $significantPoints[1][$i][0] . ', ' . $significantPoints[1][$i][1] . ']' . ($i < $arrSize - 1 ? ',' : '') . '<br />';
//}
//var_dump($significantPoints);
//echo '</pre>';
$result = Algorithm::positionOnLine(1, new GeographicalPoint(28.0643, -80.62009999999999), [new GeographicalLine(new GeographicalPoint(28.065, -80.62114), new GeographicalPoint(28.065, -80.62050000000001)), new GeographicalLine(new GeographicalPoint(28.065, -80.62050000000001), new GeographicalPoint(28.065, -80.6198)), new GeographicalLine(new GeographicalPoint(28.065, -80.6198), new GeographicalPoint(28.065, -80.619))], true);
var_dump($result);
//$lineA = Algorithm::testIntersection();
示例#12
0
 public function __construct($alg)
 {
     parent::__construct($alg);
 }
示例#13
0
        //використовуючи зворотній прохід, визначається мінімальний шлях
        $shortStack = new SplStack();
        //найкоротший шлях як стек
        $node = $target;
        $dist = 0;
        //прохід від цільового вузла до стартового
        while (isset($prevNode[$node]) && $prevNode[$node]) {
            $shortStack->push($node);
            $dist += $this->graph[$node][$prevNode[$node]];
            //додавання дистанції для попередників
            $node = $prevNode[$node];
        }
        //стек буде пустий, якщо нема шляху назад
        if ($shortStack->isEmpty()) {
            $this->res .= "Немає шляху із " . $source . " в " . $target;
        } else {
            //добавлення стартового вузла, виведення всього шляху
            $shortStack->push($source);
            $this->res .= "{$dist}:  ";
            $sep = '';
            foreach ($shortStack as $v) {
                $this->res .= $sep . $v;
                $sep = '->';
            }
        }
        return $this->res;
    }
}
$g = new Algorithm($graph, '');
$res["res"] = $g->shortestPath($_POST['source'], $_POST['target']);
echo json_encode($res);
 public function __construct($objStateGenerator)
 {
     parent::__construct($objStateGenerator);
 }
 /**
  * Creates a new time-based one-time-password instance
  *
  * @param  com.google.authenticator.Secret $secret
  * @param  int $interval If omitted, uses 30 seconds
  * @param  int $digits If omitted, defaults to 6
  * @param  string $crypto If omitted, defaults to "sha1"
  */
 public function __construct(Secret $secret, $interval = 30, $digits = 6, $crypto = 'sha1')
 {
     parent::__construct($secret, $digits, $crypto);
     $this->interval = $interval;
 }
示例#16
0
文件: Signer.php 项目: groupcash/php
 /**
  * @return Binary
  */
 public function getAddress()
 {
     return $this->service->getAddress($this->key);
 }