Weighted
========

Overview
--------

Field            Value
---------------  -------------------
Name             Weighted
Kind             aggregate
Engine           DifferenceEquations
Engine settings  defaults
Dynamics         difference equation
Step unit        step

Entities and state variables
----------------------------

Bins
~~~~
Bin  Name               Unit
---  -----------------  ----
A    State "A" \ start  item
B    State B            item

Accumulators
~~~~~~~~~~~~
Accumulator  Name
-----------  -----
moved        Moved

Stratifications
~~~~~~~~~~~~~~~
Stratification  Categories  Splits
--------------  ----------  -----------------
group           g1, g2      every compartment
tier            t1, t2      where group = g1

Compartments
~~~~~~~~~~~~
Compartment  Bin  Categories
-----------  ---  -----------------
A_g1_t1      A    group=g1, tier=t1
A_g1_t2      A    group=g1, tier=t2
A_g2         A    group=g2
B_g1_t1      B    group=g1, tier=t1
B_g1_t2      B    group=g1, tier=t2
B_g2         B    group=g2

Dynamics
--------

Compact form
~~~~~~~~~~~~
Bin Transitions:
ab (A -> B):
  A_g1_t1 -> B_g1_t1: s * k * ((B_g1_t1 + B_g1_t2) + 0.5 * B_g2) / ((A_g1_t1 + A_g1_t2 + B_g1_t1 + B_g1_t2) + 0.5 * (A_g2 + B_g2)) * A_g1_t1
  A_g1_t2 -> B_g1_t2: s * k * ((B_g1_t1 + B_g1_t2) + 0.5 * B_g2) / ((A_g1_t1 + A_g1_t2 + B_g1_t1 + B_g1_t2) + 0.5 * (A_g2 + B_g2)) * A_g1_t2
  A_g2 -> B_g2: s * k * (0.5 * (B_g1_t1 + B_g1_t2) + B_g2) / (0.5 * (A_g1_t1 + A_g1_t2 + B_g1_t1 + B_g1_t2) + (A_g2 + B_g2)) * A_g2

Total System: 6 coupled equations (2 bins × 2 group × 2 tier)

Expanded form
~~~~~~~~~~~~~
[A_g1_t1(t+Dt) - A_g1_t1(t)] / Dt = - (s * k * ((B_g1_t1 + B_g1_t2) + 0.5 * B_g2) / ((A_g1_t1 + A_g1_t2 + B_g1_t1 + B_g1_t2) + 0.5 * (A_g2 + B_g2)) * A_g1_t1)
[A_g1_t2(t+Dt) - A_g1_t2(t)] / Dt = - (s * k * ((B_g1_t1 + B_g1_t2) + 0.5 * B_g2) / ((A_g1_t1 + A_g1_t2 + B_g1_t1 + B_g1_t2) + 0.5 * (A_g2 + B_g2)) * A_g1_t2)
[A_g2(t+Dt) - A_g2(t)] / Dt = - (s * k * (0.5 * (B_g1_t1 + B_g1_t2) + B_g2) / (0.5 * (A_g1_t1 + A_g1_t2 + B_g1_t1 + B_g1_t2) + (A_g2 + B_g2)) * A_g2)
[B_g1_t1(t+Dt) - B_g1_t1(t)] / Dt = (s * k * ((B_g1_t1 + B_g1_t2) + 0.5 * B_g2) / ((A_g1_t1 + A_g1_t2 + B_g1_t1 + B_g1_t2) + 0.5 * (A_g2 + B_g2)) * A_g1_t1)
[B_g1_t2(t+Dt) - B_g1_t2(t)] / Dt = (s * k * ((B_g1_t1 + B_g1_t2) + 0.5 * B_g2) / ((A_g1_t1 + A_g1_t2 + B_g1_t1 + B_g1_t2) + 0.5 * (A_g2 + B_g2)) * A_g1_t2)
[B_g2(t+Dt) - B_g2(t)] / Dt = (s * k * (0.5 * (B_g1_t1 + B_g1_t2) + B_g2) / (0.5 * (A_g1_t1 + A_g1_t2 + B_g1_t1 + B_g1_t2) + (A_g2 + B_g2)) * A_g2)

Neighbors
~~~~~~~~~
Units are neighbors by the categories of 'group' (Groups): in a compartment of category g, neighbors_<bin> is the sum over g' of w[g][g'] times the amount of the bin in g', and neighbors the same sum over every bin. The weights w[g][g'] are:

    g1   g2
--  ---  ---
g1  1    0.5
g2  0.5  1

Schedule
--------

Each step applies every flow once, computed from the state at the start of the step: X(n + 1) = X(n) + sum of the flows. The impulses of a step act first, and its flows run from the new state.

Initialization
--------------

Bin fractions
~~~~~~~~~~~~~
Bin  Fraction            Amount
---  ------------------  ------
A    set by calibration
B    0.4                 400

Stratification fractions
~~~~~~~~~~~~~~~~~~~~~~~~
Stratification  Category  Fraction  Of
--------------  --------  --------  -----
group           g1        0.25      total
group           g2        0.75      total
tier            t1        0.5       g1
tier            t2        0.5       g1

Compartment overrides
~~~~~~~~~~~~~~~~~~~~~
Compartment  Fraction of the total  Amount
-----------  ---------------------  ------
B_g2         0.2                    200

Initial state (total 1000)
~~~~~~~~~~~~~~~~~~~~~~~~~~
Compartment  Amount
-----------  ------
A_g1_t1      0
A_g1_t2      0
A_g2         0
B_g1_t1      50
B_g1_t2      50
B_g2         200

Parameters
----------

Parameter  Value  Unit  Set by calibration  Description
---------  -----  ----  ------------------  ---------------
k          0.1          no                  rate | per step
s                       yes

Outputs
-------

Source  Outputs
------  ----------------------------------
A       A_g1_t1, A_g1_t2, A_g2
B       B_g1_t1, B_g1_t2, B_g2
moved   moved_g1_t1, moved_g1_t2, moved_g2
