Hoa central
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Hoa\Realdom\Disjunction Class Reference
Inheritance diagram for Hoa\Realdom\Disjunction:

Public Member Functions

 __construct ()
 
 __clone ()
 
 __get ($name)
 
 __call ($name, Array $arguments)
 
 _call ($name, Array $arguments=[])
 
 offsetExists ($offset)
 
 offsetGet ($offset)
 
 offsetSet ($offset, $realdom)
 
 offsetUnset ($offset)
 
 getRealdoms ()
 
 getChosenRealdom ()
 
 reset ()
 
 predicate ($q)
 
 sample (Math\Sampler $sampler=null)
 
 propagateConstraints ($type, $index)
 
 getIterator ()
 
 getUnflattenedRealdoms ()
 
 count ()
 
 setHolder (IRealdom\Holder $holder)
 
 getHolder ()
 
 accept (Visitor\Visit $visitor, &$handle=null, $eldnah=null)
 
- Public Member Functions inherited from Hoa\Visitor\Element
 accept (Visit $visitor, &$handle=null, $eldnah=null)
 

Protected Member Functions

 _offsetSet ($offset, $realdom, $backStore=true)
 

Protected Attributes

 $_originalRealdoms = []
 
 $_realdoms = []
 
 $__realdoms = []
 
 $__matches = []
 
 $_chosenRealdom = null
 
 $_constraints = []
 
 $_holder = null
 

Detailed Description

Class .

Represent a disjunction of realistic domains.

Definition at line 51 of file Disjunction.php.

Constructor & Destructor Documentation

Hoa\Realdom\Disjunction::__construct ( )

Construct.

Returns
void

Definition at line 115 of file Disjunction.php.

116  {
117  // Original realdoms are the same in every clone.
118  $this->_originalRealdoms = &$this->_originalRealdoms;
119 
120  // In the original object (not a clone):
121  $this->_realdoms = &$this->_originalRealdoms;
122 
123  return;
124  }

Member Function Documentation

Hoa\Realdom\Disjunction::__call (   $name,
Array  $arguments 
)

Declare a realistic domain: $disjunction->realdomName(arg1, arg2…). About constants: use for example: $disjunction->const(true).

Parameters
string$nameRealistic domain name.
array$argumentsArguments.
Returns
Exceptions

Definition at line 169 of file Disjunction.php.

170  {
171  $name = ucfirst(strtolower($name));
172 
173  if ('Const' === $name) {
174  $handle = $arguments;
175  Realdom::autoBoxing($handle);
176  $handle = $handle[0];
177  $arguments = [];
178  } elseif ('Variable' === $name) {
179  $handle = new Crate\Variable($arguments[0]);
180  } else {
181  if (Core\Consistency::isKeyword($name)) {
182  $name = 'Realdom' . $name;
183  }
184 
185  try {
186  $handle = dnew(
187  '(Hoathis or Hoa)\Realdom\\' . $name,
188  $arguments
189  );
190  } catch (Exception $e) {
191  throw $e;
192  } catch (Core\Exception $e) {
193  throw new Exception(
194  'Realistic domain %s() does not exist (or something ' .
195  'wrong happened).',
196  0,
197  strtolower($name),
198  $e
199  );
200  }
201  }
202 
203  $this->offsetSet(null, $handle);
204 
205  return $this;
206  }
static autoBoxing(Array &$arguments, Realdom $self=null)
Definition: Realdom.php:366
offsetSet($offset, $realdom)

Here is the call graph for this function:

Here is the caller graph for this function:

Hoa\Realdom\Disjunction::__clone ( )

Clone.

Returns
void

Definition at line 131 of file Disjunction.php.

132  {
133 
134  // Break the reference.
135  unset($this->_realdoms);
136 
137  // Create a new array of references (of realdoms).
138  $this->_realdoms = $this->_originalRealdoms;
139 
140  $this->_chosenRealdom = null;
141 
142  return;
143  }
Hoa\Realdom\Disjunction::__get (   $name)

Allow to write: $disjunction->realdom1()->or->realdom2().

Parameters
string$nameMust be “or”.
Returns

Definition at line 151 of file Disjunction.php.

152  {
153  if ('or' !== $name) {
154  return $this->$name;
155  }
156 
157  return $this;
158  }
Hoa\Realdom\Disjunction::_call (   $name,
Array  $arguments = [] 
)

Alias of $this->__call(…) if $name is not parsed by PHP.

Parameters
string$nameRealistic domain name.
array$argumentsArguments.
Returns

Definition at line 215 of file Disjunction.php.

216  {
217  return $this->__call($name, $arguments);
218  }
__call($name, Array $arguments)

Here is the call graph for this function:

Hoa\Realdom\Disjunction::_offsetSet (   $offset,
  $realdom,
  $backStore = true 
)
protected

Set a specific realistic domain.

Parameters
mixed$offsetOffset.
\Hoa\Realdom$realdomRealistic domain.
bool$backStoreBack-store in __realdoms or not.
Returns
Exceptions

Definition at line 290 of file Disjunction.php.

291  {
292  if (!($realdom instanceof Realdom)) {
293  throw new Exception(
294  'A disjunction accepts only realdom; given %s.',
295  1,
296  is_object($realdom)
297  ? get_class($realdom)
298  : gettype($realdom)
299  );
300  }
301 
302  $realdom->setConstraints($this->_constraints);
303 
304  if (null === $offset) {
305  $this->_realdoms[] = $realdom;
306 
307  if (true === $backStore) {
308  $this->__realdoms[] = &$realdom;
309  $this->__matches[] = 1;
310  }
311  } else {
312  throw new Exception('Offset %s must be null.', 2);
313  }
314 
315  return $this;
316  }

Here is the caller graph for this function:

Hoa\Realdom\Disjunction::accept ( Visitor\Visit  $visitor,
$handle = null,
  $eldnah = null 
)

Accept a visitor.

Parameters
\Hoa\Visitor\Visit$visitorVisitor.
mixed&$handleHandle (reference).
mixed$eldnahHandle (no reference).
Returns
mixed

Definition at line 510 of file Disjunction.php.

514  {
515  return $visitor->visit($this, $handle, $eldnah);
516  }
517 }
518 
519 }
520 
521 namespace {
522 
528 if (!function_exists('realdom')) {
529  function realdom()
530  {
531  return new Hoa\Realdom\Disjunction();
532  }
533 }
Hoa\Realdom\Disjunction::count ( )

Count number of realistics domains.

Returns
int

Definition at line 469 of file Disjunction.php.

470  {
471  return count($this->_realdoms);
472  }

Here is the caller graph for this function:

Hoa\Realdom\Disjunction::getChosenRealdom ( )

Get chosen realistic domain.

Returns

Definition at line 359 of file Disjunction.php.

360  {
361  return $this->_chosenRealdom;
362  }
Hoa\Realdom\Disjunction::getHolder ( )

Get holder.

Returns

Definition at line 497 of file Disjunction.php.

498  {
499  return $this->_holder;
500  }
Hoa\Realdom\Disjunction::getIterator ( )

Iterate over realistic domains.

Returns

Definition at line 449 of file Disjunction.php.

450  {
451  return new \ArrayIterator($this->_realdoms);
452  }
Hoa\Realdom\Disjunction::getRealdoms ( )

Get realistic domains.

Returns
array

Definition at line 349 of file Disjunction.php.

350  {
351  return $this->_realdoms;
352  }
Hoa\Realdom\Disjunction::getUnflattenedRealdoms ( )

Get unflattened realistic domains.

Returns
array

Definition at line 459 of file Disjunction.php.

460  {
461  return $this->__realdoms;
462  }
Hoa\Realdom\Disjunction::offsetExists (   $offset)

Check if a realistic domain exists for a specified offset.

Parameters
mixed$offsetOffset.
Returns
bool

Definition at line 226 of file Disjunction.php.

227  {
228  return array_key_exists($offset, $this->_realdoms);
229  }

Here is the caller graph for this function:

Hoa\Realdom\Disjunction::offsetGet (   $offset)

Get a specific realistic domain.

Parameters
mixed$offsetOffset.
Returns

Definition at line 237 of file Disjunction.php.

238  {
239  if (false === $this->offsetExists($offset)) {
240  return null;
241  }
242 
243  return $this->_realdoms[$offset];
244  }

Here is the call graph for this function:

Here is the caller graph for this function:

Hoa\Realdom\Disjunction::offsetSet (   $offset,
  $realdom 
)

Set a specific realistic domain.

Parameters
mixed$offsetOffset.
\Hoa\Realdom$realdomRealistic domain.
Returns
Exceptions

Definition at line 254 of file Disjunction.php.

255  {
256  if ($realdom instanceof self) {
257  foreach ($realdom as $_realdom) {
258  $this->_offsetSet(null, $_realdom);
259  }
260 
261  return $this;
262  }
263 
264  if ($realdom instanceof Crate\Variable) {
265  $this->__realdoms[] = $realdom;
266  $unfolded = 1;
267 
268  foreach ($realdom->getDomains() as $_realdom) {
269  $this->_offsetSet(null, $_realdom, false);
270  ++$unfolded;
271  }
272 
273  $this->__matches[] = $unfolded;
274 
275  return $this;
276  }
277 
278  return $this->_offsetSet($offset, $realdom);
279  }
_offsetSet($offset, $realdom, $backStore=true)

Here is the call graph for this function:

Here is the caller graph for this function:

Hoa\Realdom\Disjunction::offsetUnset (   $offset)

Unset a specific realistic domain. Index are re-computed.

Parameters
mixed$offsetOffset.
Returns
void

Definition at line 325 of file Disjunction.php.

326  {
327  if (null === $this->offsetGet($offset)) {
328  return;
329  }
330 
331  array_splice($this->__realdoms, $offset, 1);
332 
333  $acc = 0;
334 
335  for ($i = 0; $i < $offset - 1; ++$i) {
336  $acc += $this->__matches[$i];
337  }
338 
339  array_splice($this->_realdoms, $acc, $this->__matches[$i]);
340 
341  return;
342  }

Here is the call graph for this function:

Hoa\Realdom\Disjunction::predicate (   $q)

Predicate whether the sampled value belongs to the realistic domains.

Parameters
mixed$qSampled value.
Returns
boolean

Definition at line 384 of file Disjunction.php.

385  {
386  foreach ($this->_realdoms as $realdom) {
387  if (true === $realdom->predicate($q)) {
388  return true;
389  }
390  }
391 
392  return false;
393  }
Hoa\Realdom\Disjunction::propagateConstraints (   $type,
  $index 
)

Propagate constraints (public).

Parameters
string$typeType.
int$indexIndex.
Returns
void

Definition at line 435 of file Disjunction.php.

436  {
437  foreach ($this->_realdoms as $realdom) {
438  $realdom->propagateConstraints($type, $index);
439  }
440 
441  return;
442  }
Hoa\Realdom\Disjunction::reset ( )

Reset all realistic domains.

Returns
void

Definition at line 369 of file Disjunction.php.

370  {
371  foreach ($this->_realdoms as $realdom) {
372  $realdom->reset();
373  }
374 
375  return;
376  }
Hoa\Realdom\Disjunction::sample ( Math\Sampler  $sampler = null)

Sample a new value.

Parameters
\Hoa\Math\Sampler$samplerSampler.
Returns
mixed
Exceptions

Definition at line 402 of file Disjunction.php.

403  {
404  if (empty($this->_realdoms)) {
405  throw new Exception(
406  'Cannot sample because the disjunction is empty.',
407  3
408  );
409  }
410 
411  if (null === $sampler &&
412  null === $sampler = Realdom::getDefaultSampler()) {
413  throw new Exception(
414  'No sampler set. Please, use the %s::setDefaultSampler() ' .
415  'method.',
416  4,
417  __NAMESPACE__
418  );
419  }
420 
421  $m = count($this->_realdoms) - 1;
422  $i = $sampler->getInteger(0, $m);
423  $this->_chosenRealdom = $this->_realdoms[$i];
424 
425  return $this->_chosenRealdom->sample($sampler);
426  }
static getDefaultSampler()
Definition: Realdom.php:542

Here is the call graph for this function:

Hoa\Realdom\Disjunction::setHolder ( IRealdom\Holder  $holder)

Set holder.

Parameters
\Hoa\Realdom\IRealdom\Holder$holderHolder.
Returns

Definition at line 480 of file Disjunction.php.

481  {
482  $old = $holder;
483  $this->_holder = $holder;
484 
485  foreach ($this->_realdoms as $realdom) {
486  $realdom->setHolder($holder);
487  }
488 
489  return $old;
490  }

Member Data Documentation

Hoa\Realdom\Disjunction::$__matches = []
protected

Definition at line 85 of file Disjunction.php.

Hoa\Realdom\Disjunction::$__realdoms = []
protected

Definition at line 77 of file Disjunction.php.

Hoa\Realdom\Disjunction::$_chosenRealdom = null
protected

Definition at line 92 of file Disjunction.php.

Hoa\Realdom\Disjunction::$_constraints = []
protected

Definition at line 99 of file Disjunction.php.

Hoa\Realdom\Disjunction::$_holder = null
protected

Definition at line 106 of file Disjunction.php.

Hoa\Realdom\Disjunction::$_originalRealdoms = []
protected

Definition at line 62 of file Disjunction.php.

Hoa\Realdom\Disjunction::$_realdoms = []
protected

Definition at line 69 of file Disjunction.php.


The documentation for this class was generated from the following file: