2010-09-18 11:11:44 -04:00
|
|
|
<?php
|
2022-07-05 15:55:47 +02:00
|
|
|
|
2022-07-05 15:33:34 +02:00
|
|
|
namespace DNW\Skills\FactorGraphs;
|
2010-09-18 11:11:44 -04:00
|
|
|
|
2022-07-05 16:21:06 +02:00
|
|
|
class Variable implements \Stringable
|
2010-09-18 11:11:44 -04:00
|
|
|
{
|
2023-08-01 12:13:24 +00:00
|
|
|
private string $_name;
|
2022-07-05 15:55:47 +02:00
|
|
|
|
2023-08-01 12:13:24 +00:00
|
|
|
private mixed $_value;
|
2010-09-18 11:11:44 -04:00
|
|
|
|
2023-08-01 12:13:24 +00:00
|
|
|
public function __construct(string $name, private mixed $_prior)
|
2010-09-18 11:11:44 -04:00
|
|
|
{
|
2022-07-05 15:55:47 +02:00
|
|
|
$this->_name = 'Variable['.$name.']';
|
2010-09-18 11:11:44 -04:00
|
|
|
$this->resetToPrior();
|
|
|
|
}
|
|
|
|
|
2023-08-01 12:13:24 +00:00
|
|
|
public function getValue(): mixed
|
2010-09-18 11:11:44 -04:00
|
|
|
{
|
2016-05-24 16:31:21 +02:00
|
|
|
return $this->_value;
|
2010-09-18 11:11:44 -04:00
|
|
|
}
|
|
|
|
|
2023-08-01 12:13:24 +00:00
|
|
|
public function setValue(mixed $value): void
|
2016-05-24 14:10:39 +02:00
|
|
|
{
|
2016-05-24 16:31:21 +02:00
|
|
|
$this->_value = $value;
|
2010-09-18 11:11:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function resetToPrior()
|
|
|
|
{
|
|
|
|
$this->_value = $this->_prior;
|
|
|
|
}
|
|
|
|
|
2022-07-05 16:21:06 +02:00
|
|
|
public function __toString(): string
|
2010-09-18 11:11:44 -04:00
|
|
|
{
|
|
|
|
return $this->_name;
|
|
|
|
}
|
2022-07-05 15:55:47 +02:00
|
|
|
}
|