Hoa central
Public Member Functions | Protected Attributes | List of all members
Hoa\Math\Combinatorics\Combination\Gamma Class Reference
Inheritance diagram for Hoa\Math\Combinatorics\Combination\Gamma:

Public Member Functions

 __construct ($n, $k)
 
 current ()
 
 key ()
 
 next ()
 
 rewind ()
 
 valid ()
 

Protected Attributes

 $_n = 0
 
 $_k = 0
 
 $_current = null
 
 $_key = -1
 
 $_tmp = null
 
 $_i = 0
 
 $_o = 0
 
 $_last = false
 

Detailed Description

Class .

Gamma^n_k denotes the set of k-uples whose sum of elements is n. For example: Gamma^2_3 = {(2, 0, 0), (1, 1, 0), (1, 0, 1), (0, 2, 0), (0, 1, 1), (0, 0, 2)}. For any k-uple γ and any α in {1, …, k}, γ_α denotes the α-th element of γ. This class is identical to ::Gamma with a “yield” keyword.

Definition at line 53 of file Gamma.php.

Constructor & Destructor Documentation

Hoa\Math\Combinatorics\Combination\Gamma::__construct (   $n,
  $k 
)

Constructor.

Parameters
int$nn.
int$kk.
Returns
void

Definition at line 121 of file Gamma.php.

122  {
123  $this->_n = $n;
124  $this->_k = $k;
125 
126  return;
127  }

Member Function Documentation

Hoa\Math\Combinatorics\Combination\Gamma::current ( )

Get current γ.

Returns
array

Definition at line 134 of file Gamma.php.

135  {
136  return $this->_current;
137  }
Hoa\Math\Combinatorics\Combination\Gamma::key ( )

Get current α.

Returns
int

Definition at line 144 of file Gamma.php.

145  {
146  return $this->_key;
147  }
Hoa\Math\Combinatorics\Combination\Gamma::next ( )

Compute γ_{α + 1}.

Returns
void

Definition at line 154 of file Gamma.php.

155  {
156  return;
157  }
Hoa\Math\Combinatorics\Combination\Gamma::rewind ( )

Rewind iterator.

Returns
void

Definition at line 164 of file Gamma.php.

165  {
166  $this->_current = [];
167  $this->_tmp = null;
168  $this->_i = 0;
169  $this->_o = 0 === $this->_n
170  ? [0]
171  : array_fill(0, $this->_n, 0);
172  $this->_o[0] = $this->_k;
173  $this->_last = false;
174 
175  return;
176  }
Hoa\Math\Combinatorics\Combination\Gamma::valid ( )

Compute γ_α.

Returns
bool

Definition at line 183 of file Gamma.php.

184  {
185  if (true === $this->_last) {
186  return false;
187  }
188 
189  if (0 === $this->_n) {
190  return false;
191  }
192 
193  if ($this->_k == $this->_o[$this->_i = $this->_n - 1]) {
194  $this->_last = true;
195  $this->_current = $this->_o;
196  ++$this->_key;
197 
198  return true;
199  }
200 
201  $this->_current = $this->_o;
202  ++$this->_key;
203 
204  $this->_tmp = $this->_o[$this->_i];
205  $this->_o[$this->_i] = 0;
206 
207  while ($this->_o[$this->_i] == 0) {
208  --$this->_i;
209  }
210 
211  --$this->_o[$this->_i];
212  $this->_o[$this->_i + 1] = $this->_tmp + 1;
213 
214  return true;
215  }

Member Data Documentation

Hoa\Math\Combinatorics\Combination\Gamma::$_current = null
protected

Definition at line 74 of file Gamma.php.

Hoa\Math\Combinatorics\Combination\Gamma::$_i = 0
protected

Definition at line 95 of file Gamma.php.

Hoa\Math\Combinatorics\Combination\Gamma::$_k = 0
protected

Definition at line 67 of file Gamma.php.

Hoa\Math\Combinatorics\Combination\Gamma::$_key = -1
protected

Definition at line 81 of file Gamma.php.

Hoa\Math\Combinatorics\Combination\Gamma::$_last = false
protected

Definition at line 110 of file Gamma.php.

Hoa\Math\Combinatorics\Combination\Gamma::$_n = 0
protected

Definition at line 60 of file Gamma.php.

Hoa\Math\Combinatorics\Combination\Gamma::$_o = 0
protected

Definition at line 102 of file Gamma.php.

Hoa\Math\Combinatorics\Combination\Gamma::$_tmp = null
protected

Definition at line 88 of file Gamma.php.


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