Skip to content

Commit

Permalink
Update example 'no subsidy'
Browse files Browse the repository at this point in the history
  • Loading branch information
julianmendez committed Feb 25, 2024
1 parent 2366db0 commit 90127fe
Show file tree
Hide file tree
Showing 12 changed files with 145 additions and 20 deletions.
22 changes: 22 additions & 0 deletions core/src/main/scala/soda/tiles/fairness/tile/AllSatisfyPTile.soda
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

directive lean
import Soda.tiles.fairness.tool.TileMessage

/**
* This tile takes a sequence of measures and returns 'true' when all the elements in the input
* satisfy a property.
*/

class AllSatisfyPTile

abstract
p : Measure -> Boolean

apply (message : TileMessage [Seq [Measure] ] ) : TileMessage [Boolean] =
TileMessageBuilder .mk .build (message .context) (message .outcome) (
( (message .contents)
.forall (lambda actor --> p (actor) ) )
)

end

Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ directive lean
import Soda.tiles.fairness.tool.TileMessage

/**
* This tile takes a sequence of actors as input and returns the a sequence of measures, such
* that, each position in output sequence is the projection of an attribute for its respective
* actor from the input.
* This tile takes a sequence of actors as input and returns the sequence of measures, such
* that, each position in the output sequence is the application of a function on the
* corresponding actor in the input.
*/

class AttributePTile
Expand Down
22 changes: 22 additions & 0 deletions core/src/main/scala/soda/tiles/fairness/tile/MapPTile.soda
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

directive lean
import Soda.tiles.fairness.tool.TileMessage

/**
* This tile takes a sequence of measures as input and applies a function to each of the
* elements in the input, and return the result as output.
*/

class MapPTile

abstract
p : Measure -> Measure

apply (message : TileMessage [Seq [Measure] ] ) : TileMessage [Seq [Measure] ] =
TileMessageBuilder .mk .build (message .context) (message .outcome) (
( (message .contents)
.map (lambda measure --> p (measure) ) )
)

end

68 changes: 65 additions & 3 deletions core/src/main/scala/soda/tiles/fairness/tile/Package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,40 @@ import Soda.tiles.fairness.tool.TileMessage
*/

/**
* This tile takes a sequence of actors as input and returns the a sequence of measures, such
* that, each position in output sequence is the projection of an attribute for its respective
* actor from the input.
* This tile takes a sequence of measures and returns 'true' when all the elements in the input
* satisfy a property.
*/

trait AllSatisfyPTile
{

def p : Measure => Boolean

def apply (message : TileMessage [Seq [Measure] ] ) : TileMessage [Boolean] =
TileMessageBuilder .mk .build (message .context) (message .outcome) (
( (message .contents)
.forall ( actor => p (actor) ) )
)

}

case class AllSatisfyPTile_ (p : Measure => Boolean) extends AllSatisfyPTile

object AllSatisfyPTile {
def mk (p : Measure => Boolean) : AllSatisfyPTile =
AllSatisfyPTile_ (p)
}


/*
directive lean
import Soda.tiles.fairness.tool.TileMessage
*/

/**
* This tile takes a sequence of actors as input and returns the sequence of measures, such
* that, each position in the output sequence is the application of a function on the
* corresponding actor in the input.
*/

trait AttributePTile
Expand Down Expand Up @@ -383,6 +414,37 @@ object FalsePosTile {
}


/*
directive lean
import Soda.tiles.fairness.tool.TileMessage
*/

/**
* This tile takes a sequence of measures as input and applies a function to each of the
* elements in the input, and return the result as output.
*/

trait MapPTile
{

def p : Measure => Measure

def apply (message : TileMessage [Seq [Measure] ] ) : TileMessage [Seq [Measure] ] =
TileMessageBuilder .mk .build (message .context) (message .outcome) (
( (message .contents)
.map ( measure => p (measure) ) )
)

}

case class MapPTile_ (p : Measure => Measure) extends MapPTile

object MapPTile {
def mk (p : Measure => Measure) : MapPTile =
MapPTile_ (p)
}


/*
directive lean
import Soda.tiles.fairness.tool.TileMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@ class CcsNoSubsidyPipeline
sigma : Measure -> Measure -> Measure
p_utility : Resource -> Measure

all_equal_tile = AllEqualTile .mk
is_equals_0 (measure : Measure) : Boolean =
match measure
case Some (0) ==> true
case otherwise ==> false

all_satisfy_p_tile = AllSatisfyPTile .mk (is_equals_0)

received_sigma_p_tile = ReceivedSigmaPTile .mk (sigma) (p_utility)

all_actor_tile = AllActorTile .mk

apply (message : TileMessage [Boolean] ) : TileMessage [Boolean] =
all_equal_tile .apply (
all_satisfy_p_tile .apply (
received_sigma_p_tile .apply (
all_actor_tile .apply (message)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

class CcsPerFamily
class CcsPerFamilyPipeline

abstract
sigma : Measure -> Measure -> Measure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ import soda.tiles.fairness.tile.AllActorTripleTile
import soda.tiles.fairness.tile.AllAtLeastTile
import soda.tiles.fairness.tile.AllEqual1Tile
import soda.tiles.fairness.tile.AllEqualTile
import soda.tiles.fairness.tile.AllSatisfyPTile
import soda.tiles.fairness.tile.AttributePTile
import soda.tiles.fairness.tile.CorrelationTile
import soda.tiles.fairness.tile.DecisionTile
import soda.tiles.fairness.tile.FalsePosTile
import soda.tiles.fairness.tile.MapPTile
import soda.tiles.fairness.tile.NeededPTile
import soda.tiles.fairness.tile.PredictionPTile
import soda.tiles.fairness.tile.ReceivedSigmaPTile
Expand All @@ -45,14 +47,20 @@ trait CcsNoSubsidyPipeline
def sigma : Measure => Measure => Measure
def p_utility : Resource => Measure

lazy val all_equal_tile = AllEqualTile .mk
def is_equals_0 (measure : Measure) : Boolean =
measure match {
case Some (0) => true
case otherwise => false
}

lazy val all_satisfy_p_tile = AllSatisfyPTile .mk (is_equals_0)

lazy val received_sigma_p_tile = ReceivedSigmaPTile .mk (sigma) (p_utility)

lazy val all_actor_tile = AllActorTile .mk

def apply (message : TileMessage [Boolean] ) : TileMessage [Boolean] =
all_equal_tile .apply (
all_satisfy_p_tile .apply (
received_sigma_p_tile .apply (
all_actor_tile .apply (message)
)
Expand All @@ -68,7 +76,7 @@ object CcsNoSubsidyPipeline {
}


trait CcsPerFamily
trait CcsPerFamilyPipeline
{

def sigma : Measure => Measure => Measure
Expand All @@ -89,10 +97,10 @@ trait CcsPerFamily

}

case class CcsPerFamily_ (sigma : Measure => Measure => Measure, p_utility : Resource => Measure) extends CcsPerFamily
case class CcsPerFamilyPipeline_ (sigma : Measure => Measure => Measure, p_utility : Resource => Measure) extends CcsPerFamilyPipeline

object CcsPerFamily {
def mk (sigma : Measure => Measure => Measure) (p_utility : Resource => Measure) : CcsPerFamily =
CcsPerFamily_ (sigma, p_utility)
object CcsPerFamilyPipeline {
def mk (sigma : Measure => Measure => Measure) (p_utility : Resource => Measure) : CcsPerFamilyPipeline =
CcsPerFamilyPipeline_ (sigma, p_utility)
}

Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ import
soda.tiles.fairness.tile.AllAtLeastTile
soda.tiles.fairness.tile.AllEqual1Tile
soda.tiles.fairness.tile.AllEqualTile
soda.tiles.fairness.tile.AllSatisfyPTile
soda.tiles.fairness.tile.AttributePTile
soda.tiles.fairness.tile.CorrelationTile
soda.tiles.fairness.tile.DecisionTile
soda.tiles.fairness.tile.FalsePosTile
soda.tiles.fairness.tile.MapPTile
soda.tiles.fairness.tile.NeededPTile
soda.tiles.fairness.tile.PredictionPTile
soda.tiles.fairness.tile.ReceivedSigmaPTile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CcsNoSubsidyPipelineSpec ()
no_subsidy_pipeline .apply (scenario) .contents
)
) (
expected := Seq (true , true , true , false , false , false , false , false)
expected := Seq (true , false , false , false , false , false , false , false)
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class CcsPerFamilyPipelineSpec ()
all_cases = _mm .all_cases

no_subsidy_pipeline =
CcsNoSubsidyPipeline .mk (_mm .measure_sum) (_mm .resource_value)
CcsPerFamilyPipeline .mk (_mm .measure_sum) (_mm .resource_value)

test ("per family on all outcomes") (
check (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ import soda.tiles.fairness.tile.AllActorTripleTile
import soda.tiles.fairness.tile.AllAtLeastTile
import soda.tiles.fairness.tile.AllEqual1Tile
import soda.tiles.fairness.tile.AllEqualTile
import soda.tiles.fairness.tile.AllSatisfyPTile
import soda.tiles.fairness.tile.AttributePTile
import soda.tiles.fairness.tile.CorrelationTile
import soda.tiles.fairness.tile.DecisionTile
import soda.tiles.fairness.tile.FalsePosTile
import soda.tiles.fairness.tile.MapPTile
import soda.tiles.fairness.tile.NeededPTile
import soda.tiles.fairness.tile.PredictionPTile
import soda.tiles.fairness.tile.ReceivedSigmaPTile
Expand Down Expand Up @@ -67,7 +69,7 @@ case class CcsNoSubsidyPipelineSpec ()
no_subsidy_pipeline .apply (scenario) .contents
)
) (
expected = Seq (true , true , true , false , false , false , false , false)
expected = Seq (true , false , false , false , false , false , false , false)
)
)

Expand All @@ -87,7 +89,7 @@ case class CcsPerFamilyPipelineSpec ()
lazy val all_cases = _mm .all_cases

lazy val no_subsidy_pipeline =
CcsNoSubsidyPipeline .mk (_mm .measure_sum) (_mm .resource_value)
CcsPerFamilyPipeline .mk (_mm .measure_sum) (_mm .resource_value)

test ("per family on all outcomes") (
check (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ import
soda.tiles.fairness.tile.AllAtLeastTile
soda.tiles.fairness.tile.AllEqual1Tile
soda.tiles.fairness.tile.AllEqualTile
soda.tiles.fairness.tile.AllSatisfyPTile
soda.tiles.fairness.tile.AttributePTile
soda.tiles.fairness.tile.CorrelationTile
soda.tiles.fairness.tile.DecisionTile
soda.tiles.fairness.tile.FalsePosTile
soda.tiles.fairness.tile.MapPTile
soda.tiles.fairness.tile.NeededPTile
soda.tiles.fairness.tile.PredictionPTile
soda.tiles.fairness.tile.ReceivedSigmaPTile
Expand Down

0 comments on commit 90127fe

Please sign in to comment.