trueskill/PHPSkills/FactorGraphs/Variable.php

74 lines
1.2 KiB
PHP
Raw Normal View History

<?php
namespace Moserware\Skills\FactorGraphs;
class Variable
{
private $_name;
private $_prior;
private $_value;
2010-09-30 12:25:31 +00:00
public function __construct($name, &$prior)
{
$this->_name = "Variable[" . $name . "]";
$this->_prior = $prior;
$this->resetToPrior();
}
public function &getValue()
{
2010-10-03 23:21:55 +00:00
$value = &$this->_value;
2010-09-30 12:25:31 +00:00
return $value;
}
public function setValue(&$value)
2010-10-03 23:21:55 +00:00
{
$this->_value = &$value;
}
public function resetToPrior()
{
$this->_value = $this->_prior;
}
public function __toString()
{
return $this->_name;
}
}
class DefaultVariable extends Variable
{
public function __construct()
{
parent::__construct("Default", null);
}
2010-09-30 12:25:31 +00:00
public function &getValue()
{
return null;
}
2010-09-30 12:25:31 +00:00
public function setValue(&$value)
{
throw new Exception();
}
}
class KeyedVariable extends Variable
{
private $_key;
public function __construct(&$key, $name, &$prior)
{
parent::__construct($name, $prior);
$this->_key = &$key;
}
public function &getKey()
{
$key = &$this->_key;
return $key;
}
}
?>