-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from julianmendez/development
Example for child care subsidy
- Loading branch information
Showing
6 changed files
with
229 additions
and
8 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
...ples/src/main/scala/soda/tiles/fairness/example/childcaresubsidy/CcsPerChildPipeline.soda
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
|
||
directive lean | ||
import Soda.tiles.fairness.tool.TileMessage | ||
import Soda.tiles.fairness.tile.AtLeastTile | ||
import Soda.tiles.fairness.tile.NeededPTile | ||
import Soda.tiles.fairness.tile.ReceivedSigmaPTile | ||
import Soda.tiles.fairness.tile.UnzipPairFstTile | ||
import Soda.tiles.fairness.tile.UnzipPairSndTile | ||
import Soda.tiles.fairness.tile.ZipTile | ||
|
||
|
||
/** | ||
* This pipeline returns 'true' when all the actors in the input receive a resource that | ||
* satisfies their needs, and 'false' otherwise. | ||
*/ | ||
|
||
class CcsPerChildPipeline | ||
|
||
abstract | ||
sigma : Measure -> Measure -> Measure | ||
children : Actor -> Measure | ||
utility : Resource -> Measure | ||
|
||
all_equal_tile = AllEqualTile .mk | ||
|
||
received_sigma_p_tile = ReceivedSigmaPTile .mk (sigma) (utility) | ||
|
||
children_tile = AttributePTile .mk (children) | ||
|
||
all_actor_pair_tile = AllActorPairTile .mk | ||
|
||
_division_with_2 (val0 : Int) (val1 : Int) : Measure = | ||
if val1 == 0 | ||
then None | ||
else Some (val0 / val1) | ||
|
||
_division_with (val0 : Int) (m1 : Measure) : Measure = | ||
match m1 | ||
case Some (val1) ==> _division_with_2 (val0) (val1) | ||
case None ==> None | ||
|
||
division (m0 : Measure) (m1 : Measure) : Measure = | ||
match m0 | ||
case Some (val0) ==> _division_with (val0) (m1) | ||
case None ==> None | ||
|
||
division_tile = SigmaTile .mk (division) | ||
|
||
unzip_fst_tile = UnzipPairFstTile .mk | ||
|
||
unzip_snd_tile = UnzipPairSndTile .mk | ||
|
||
zip_tile = ZipTile .mk | ||
|
||
get_branch_0 (message : TileMessage [Seq [TilePair [Actor] [Actor] ] ] ) | ||
: TileMessage [Seq [Measure] ] = | ||
received_sigma_p_tile .apply (unzip_fst_tile .apply (message) ) | ||
|
||
get_branch_1 (message : TileMessage [Seq [TilePair [Actor] [Actor] ] ] ) | ||
: TileMessage [Seq [Measure] ] = | ||
children_tile .apply (unzip_snd_tile .apply (message) ) | ||
|
||
zip_branches (message : TileMessage [Seq [TilePair [Actor] [Actor] ] ] ) | ||
: TileMessage [Seq [TilePair [Measure] [Measure] ] ] = | ||
zip_tile .apply (get_branch_0 (message) ) (get_branch_1 (message) ) | ||
|
||
apply (message : TileMessage [Boolean] ) : TileMessage [Boolean] = | ||
all_equal_tile .apply ( | ||
division_tile .apply ( | ||
zip_branches ( | ||
all_actor_pair_tile .apply (message) | ||
) | ||
) | ||
) | ||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
.../src/test/scala/soda/tiles/fairness/example/childcaresubsidy/CcsPerChildPipelineSpec.soda
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
class CcsPerChildPipelineSpec () | ||
extends | ||
AnyFunSuite | ||
|
||
check [A : Type] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = | ||
assert (obtained == expected) | ||
|
||
_mm = ChildCareSubsidyScenarioExample .mk | ||
|
||
all_cases = _mm .all_cases | ||
|
||
per_child_pipeline = | ||
CcsPerChildPipeline .mk (_mm .measure_sum) (_mm .actor_children) (_mm .resource_value) | ||
|
||
test ("per child on all outcomes") ( | ||
check ( | ||
obtained := all_cases | ||
.map (lambda scenario --> | ||
per_child_pipeline .apply (scenario) .contents | ||
) | ||
) ( | ||
expected := Seq (true , false , false , false , true , false , false , true) | ||
) | ||
) | ||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters