Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application to run the examples #12

Merged
merged 11 commits into from
Mar 16, 2024
7 changes: 7 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ lazy val examples =
.dependsOn(core)
.settings(
commonSettings,
/**
* YAML 1.2 parser
* [[https://bitbucket.org/asomov/snakeyaml-engine]]
* [[https://repo1.maven.org/maven2/org/snakeyaml/snakeyaml-engine/]]
*/
libraryDependencies += "org.snakeyaml" % "snakeyaml-engine" % "2.7",
assembly / assemblyJarName := "examples-" + version.value + ".jar"
)

Expand All @@ -72,6 +78,7 @@ lazy val root =
.dependsOn(docs, core, examples)
.settings(
commonSettings,
assembly / mainClass := Some("soda.tiles.fairness.example.main.EntryPoint"),
assembly / assemblyJarName := "tiles-" + version.value + ".jar"
)

4 changes: 2 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ are:
[ResourceAllocationScenarioExample]: https://github.com/julianmendez/tiles/blob/master/core/src/test/scala/soda/tiles/fairness/pipeline/ResourceAllocationScenarioExample.soda
[EqualityPipelineSpec]: https://github.com/julianmendez/tiles/blob/master/core/src/test/scala/soda/tiles/fairness/pipeline/EqualityPipelineSpec.soda
[EquityPipelineSpec]: https://github.com/julianmendez/tiles/blob/master/core/src/test/scala/soda/tiles/fairness/pipeline/EquityPipelineSpec.soda
[ccs-example]: ccs_example.html
[scoring-example]: scoring_example.html
[ccs-example]: https://julianmendez.github.io/tiles/ccs_example.html
[scoring-example]: https://julianmendez.github.io/tiles/scoring_example.html

<script>
window.mermaid.init(undefined, document.querySelectorAll('.language-mermaid'));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

class CcsAcromagatInstance

abstract
actors : Seq [Actor]
resources : Seq [Resource]
outcome : Outcome
actor_children_map : Map [Actor] [Measure]
actor_adults_map : Map [Actor] [Measure]
actor_income_map : Map [Actor] [Measure]
resource_value_map : Map [Resource] [Measure]
pipelines : Seq [String]

_add_value_to (value : Int) (m : Measure) : Measure =
match m
case Some (other_value) ==> Some (value + other_value)
case None ==> None

measure_sum (a : Measure) (b : Measure) : Measure =
match a
case Some (value) ==> _add_value_to (value) (b)
case None ==> None

get_or_else [A : Type] (map : Map [A] [Measure] ) (key : A) (default : Measure) : Measure =
match map .get (key)
case Some (value) ==> value
case None ==> default

actor_children (actor : Actor) : Measure =
get_or_else [Actor] (actor_children_map) (actor) (Some (-1) )

actor_adults (actor : Actor) : Measure =
get_or_else [Actor] (actor_adults_map) (actor) (Some (-1) )

actor_income (actor : Actor) : Measure =
get_or_else [Actor] (actor_income_map) (actor) (Some (-1) )

resource_value (resource : Resource) : Measure =
get_or_else [Resource] (resource_value_map) (resource) (Some (-1) )

context = "ChildCareSubsidy"

initial_message : TileMessage [Boolean] =
TileMessageBuilder .mk .build (context) (outcome) (true)

end

Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@

class CcsAcromagatInstanceBuilder

abstract

import
soda.tiles.fairness.example.parser.YamlParser
java.io.BufferedReader
java.io.Reader

actors_key = "actors"

resources_key = "resources"

outcome_key = "outcome"

actor_children_key = "actor_children"

actor_adults_key = "actor_adults"

actor_income_key = "actor_income"

resource_value_key = "resource_value"

pipelines_key = "pipelines"

to_measure (s : String) : Measure =
s .toIntOption

_get_actors (m : Map [String] [Seq [Tuple2 [String] [String] ] ] )
: Seq [Actor] =
m .getOrElse (actors_key , None)
.iterator
.map (lambda pair --> pair ._1)
.toSeq

_get_resources (m : Map [String] [Seq [Tuple2 [String] [String] ] ] )
: Seq [Resource] =
m .getOrElse (resources_key , None)
.iterator
.map (lambda pair --> pair ._1)
.toSeq

_get_outcome (m : Map [String] [Seq [Tuple2 [String] [String] ] ] )
: Outcome =
Outcome .mk (
m .getOrElse (outcome_key , None)
.iterator
.map(lambda pair --> Assignment .mk (pair._1) (pair ._2) )
.toSeq
)

_get_actor_children_map (m : Map [String] [Seq [Tuple2 [String] [String] ] ] )
: Map [Actor] [Measure] =
m .getOrElse (actor_children_key , None)
.iterator
.map (lambda pair --> Tuple2 (pair ._1 , to_measure (pair ._2) ) )
.toMap

_get_actor_adults_map (m : Map [String] [Seq [Tuple2 [String] [String] ] ] )
: Map [Actor] [Measure] =
m .getOrElse (actor_adults_key , None)
.iterator
.map (lambda pair --> Tuple2 (pair ._1 , to_measure (pair ._2) ) )
.toMap

_get_actor_income_map (m : Map [String] [Seq [Tuple2 [String] [String] ] ] )
: Map [Actor] [Measure] =
m .getOrElse (actor_income_key , None)
.iterator
.map (lambda pair --> Tuple2 (pair ._1 , to_measure (pair ._2) ) )
.toMap

_get_resource_value_map (m : Map [String] [Seq [Tuple2 [String] [String] ] ] )
: Map [Resource] [Measure] =
m .getOrElse (resource_value_key , None)
.iterator
.map (lambda pair --> Tuple2 (pair ._1 , to_measure (pair ._2) ) )
.toMap

_get_pipelines (m : Map [String] [Seq [Tuple2 [String] [String] ] ] )
: Seq [String] =
m .getOrElse (pipelines_key , None)
.iterator
.map (lambda pair --> pair ._1)
.toSeq

_build_from_map (m : Map [String] [Seq [Tuple2 [String] [String] ] ] )
: Option [CcsAcromagatInstance] =
Some (
CcsAcromagatInstance .mk (
_get_actors (m) ) (
_get_resources (m) ) (
_get_outcome (m) ) (
_get_actor_children_map (m) ) (
_get_actor_adults_map (m) ) (
_get_actor_income_map (m) ) (
_get_resource_value_map (m) ) (
_get_pipelines (m)
)
)

build (s : Seq [Seq [Tuple2 [String] [Seq [Tuple2 [String] [String] ] ] ] ] )
: Option [CcsAcromagatInstance] =
match s
case a +: as ==> _build_from_map (a .toMap)
case otherwise ==> None

from_yaml (reader : Reader) : Option [CcsAcromagatInstance] =
build (YamlParser .mk .parse (reader) )

end

Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

class CcsNoSubsidyPipeline
extends
CcsPipeline

abstract
sigma : Measure -> Measure -> Measure
Expand All @@ -23,4 +25,7 @@ class CcsNoSubsidyPipeline
)
)

runner : TileMessage [Boolean] -> TileMessage [Boolean] =
lambda message --> apply (message)

end
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import Soda.tiles.fairness.tile.ZipTile
*/

class CcsPerChildPipeline
extends
CcsPipeline

abstract
sigma : Measure -> Measure -> Measure
Expand Down Expand Up @@ -73,5 +75,7 @@ class CcsPerChildPipeline
)
)

end
runner : TileMessage [Boolean] -> TileMessage [Boolean] =
lambda message --> apply (message)

end
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

class CcsPerFamilyPipeline
extends
CcsPipeline

abstract
sigma : Measure -> Measure -> Measure
Expand All @@ -18,4 +20,7 @@ class CcsPerFamilyPipeline
)
)

runner : TileMessage [Boolean] -> TileMessage [Boolean] =
lambda message --> apply (message)

end
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

class CcsPipeline

abstract
runner : TileMessage [Boolean] -> TileMessage [Boolean]

run (initial : TileMessage [Boolean] ) : TileMessage [Boolean] =
runner (initial)

end

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

class CcsPipelineFactory

abstract

get_pipeline (name : String) (m : CcsAcromagatInstance) : Option [CcsPipeline] =
if name == "CcsNoSubsidyPipeline"
then Some (
CcsNoSubsidyPipeline .mk (m .measure_sum) (m .resource_value) )
else if name == "CcsPerChildPipeline"
then Some (
CcsPerChildPipeline .mk (m .measure_sum) (m .actor_children) (m .resource_value) )
else if name == "CcsPerFamilyPipeline"
then Some (
CcsPerFamilyPipeline .mk (m .measure_sum) (m .resource_value) )
else if name == "CcsSingleGuardianPipeline"
then Some (
CcsSingleGuardianPipeline .mk (m .measure_sum) (m .actor_adults) (m .resource_value) )
else None

end


Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

class CcsSingleGuardianPipeline
extends
CcsPipeline

abstract
sigma : Measure -> Measure -> Measure
Expand Down Expand Up @@ -71,4 +73,7 @@ class CcsSingleGuardianPipeline
)
)

runner : TileMessage [Boolean] -> TileMessage [Boolean] =
lambda message --> apply (message)

end
Loading
Loading