From 074b5e8077639b36f1ff24173a6cfdf488ad7b3a Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Sun, 18 Feb 2024 16:46:59 +0100 Subject: [PATCH] Simplify Actor, Resource, and Context types --- .../soda/tiles/fairness/tool/Entity.soda | 36 ++---------- .../soda/tiles/fairness/tool/Package.scala | 58 ++----------------- .../soda/tiles/fairness/tile/Package.scala | 25 ++++---- .../soda/tiles/fairness/tile/Package.soda | 3 - .../ResourceAllocationScenarioExample.soda | 14 ++--- .../fairness/tile/ScoringScenarioExample.soda | 8 +-- 6 files changed, 30 insertions(+), 114 deletions(-) diff --git a/tiles/src/main/scala/soda/tiles/fairness/tool/Entity.soda b/tiles/src/main/scala/soda/tiles/fairness/tool/Entity.soda index 2447f9b..965e730 100644 --- a/tiles/src/main/scala/soda/tiles/fairness/tool/Entity.soda +++ b/tiles/src/main/scala/soda/tiles/fairness/tool/Entity.soda @@ -1,36 +1,14 @@ -class Actor - extends - Comparable [Actor] - - abstract - id : String +class Identifier = String - compareTo (other : Actor) : Int = - id .compareTo (other .id) - @override - toString : String = - id +class Actor = Identifier -end +class Resource = Identifier -class Resource - extends - Comparable [Resource] - abstract - id : String - - compareTo (other : Resource) : Int = - id .compareTo (other .id) - - @override - toString : String = - id - -end +class Context = Identifier class Measure @@ -86,9 +64,3 @@ class Outcome end -class Context - - abstract - -end - diff --git a/tiles/src/main/scala/soda/tiles/fairness/tool/Package.scala b/tiles/src/main/scala/soda/tiles/fairness/tool/Package.scala index 1e2ccd8..8141284 100644 --- a/tiles/src/main/scala/soda/tiles/fairness/tool/Package.scala +++ b/tiles/src/main/scala/soda/tiles/fairness/tool/Package.scala @@ -8,51 +8,13 @@ package soda.tiles.fairness.tool -trait Actor - extends - Comparable [Actor] -{ - - def id : String - - def compareTo (other : Actor) : Int = - id .compareTo (other .id) +type Identifier = String - override - lazy val toString : String = - id +type Actor = Identifier -} +type Resource = Identifier -case class Actor_ (id : String) extends Actor - -object Actor { - def mk (id : String) : Actor = - Actor_ (id) -} - -trait Resource - extends - Comparable [Resource] -{ - - def id : String - - def compareTo (other : Resource) : Int = - id .compareTo (other .id) - - override - lazy val toString : String = - id - -} - -case class Resource_ (id : String) extends Resource - -object Resource { - def mk (id : String) : Resource = - Resource_ (id) -} +type Context = Identifier trait Measure extends @@ -125,20 +87,8 @@ object Outcome { Outcome_ (assignments) } -trait Context -{ - -} - -case class Context_ () extends Context - -object Context { - def mk : Context = - Context_ () -} - /** * r_{x,y} =\frac{\sum _{i=1}^{n}(x_{i} - \bar{x})(y_{i} - diff --git a/tiles/src/test/scala/soda/tiles/fairness/tile/Package.scala b/tiles/src/test/scala/soda/tiles/fairness/tile/Package.scala index 3d45e74..95c239b 100644 --- a/tiles/src/test/scala/soda/tiles/fairness/tile/Package.scala +++ b/tiles/src/test/scala/soda/tiles/fairness/tile/Package.scala @@ -6,17 +6,14 @@ package soda.tiles.fairness.tile import org.scalatest.funsuite.AnyFunSuite import soda.tiles.fairness.tool.Actor -import soda.tiles.fairness.tool.Actor_ import soda.tiles.fairness.tool.Assignment import soda.tiles.fairness.tool.Assignment_ import soda.tiles.fairness.tool.Context -import soda.tiles.fairness.tool.Context_ import soda.tiles.fairness.tool.Measure import soda.tiles.fairness.tool.Measure_ import soda.tiles.fairness.tool.Outcome import soda.tiles.fairness.tool.Outcome_ import soda.tiles.fairness.tool.Resource -import soda.tiles.fairness.tool.Resource_ import soda.tiles.fairness.tool.TileMessage import soda.tiles.fairness.tool.TileMessage_ import soda.tiles.fairness.tool.TileMessageBuilder @@ -132,17 +129,17 @@ trait ResourceAllocationScenarioExample def measure_sum (a : Measure) (b : Measure) : Measure = Measure_ (a .value + b .value) - lazy val resource0 = Resource_ ("small box - 0.1 m") + lazy val resource0 = "small box - 0.1 m" - lazy val resource1 = Resource_ ("medium box - 0.2 m") + lazy val resource1 = "medium box - 0.2 m" - lazy val resource2 = Resource_ ("large box - 0.3 m") + lazy val resource2 = "large box - 0.3 m" - lazy val actor0 = Actor_ ("Anna A") + lazy val actor0 = "Anna A" - lazy val actor1 = Actor_ ("Bob B") + lazy val actor1 = "Bob B" - lazy val actor2 = Actor_ ("Charlie C") + lazy val actor2 = "Charlie C" lazy val actor_need_map : Map [Actor, Measure] = Seq ( Tuple2 [Actor, Measure] (actor0 , Measure_ (30) ) , @@ -162,7 +159,7 @@ trait ResourceAllocationScenarioExample def resource_height (resource : Resource) : Measure = resource_height_map .getOrElse (resource , Measure_ (-1) ) - lazy val context = Context_ () + lazy val context = "context" lazy val outcome0 : Outcome = Outcome_ ( @@ -232,11 +229,11 @@ trait ScoringScenarioExample "Alice", "Benjamin", "Charlotte", "Daniel", "Emily", "Fiona", "George", "Hannah", "Isaac", "James", "Kevin", "Lily", "Matthew", "Natalie", "Olivia", "Quinn", "Peter", "Rachel", "Sarah", "Timothy", "Ursula", "Victoria", "William", "Xavier", "Yasmine", "Zachary" - ) .map ( name => Actor_ (name) ) + ) - private lazy val _resource_zero : Resource = Resource_ ("0") + private lazy val _resource_zero : Resource = "0" - private lazy val _resource_one : Resource = Resource_ ("1") + private lazy val _resource_one : Resource = "1" private lazy val _measure_zero : Measure = Measure_ (0) @@ -357,7 +354,7 @@ trait ScoringScenarioExample ) _measure_zero else _measure_one - lazy val context = Context_ () + lazy val context = "context" lazy val initial_unbiased : TileMessage [Boolean] = TileMessageBuilder_ () .build (context) (unbiased_outcome) (true) diff --git a/tiles/src/test/scala/soda/tiles/fairness/tile/Package.soda b/tiles/src/test/scala/soda/tiles/fairness/tile/Package.soda index a7e7182..40f73e4 100644 --- a/tiles/src/test/scala/soda/tiles/fairness/tile/Package.soda +++ b/tiles/src/test/scala/soda/tiles/fairness/tile/Package.soda @@ -7,17 +7,14 @@ package soda.tiles.fairness.tile import org.scalatest.funsuite.AnyFunSuite soda.tiles.fairness.tool.Actor - soda.tiles.fairness.tool.Actor_ soda.tiles.fairness.tool.Assignment soda.tiles.fairness.tool.Assignment_ soda.tiles.fairness.tool.Context - soda.tiles.fairness.tool.Context_ soda.tiles.fairness.tool.Measure soda.tiles.fairness.tool.Measure_ soda.tiles.fairness.tool.Outcome soda.tiles.fairness.tool.Outcome_ soda.tiles.fairness.tool.Resource - soda.tiles.fairness.tool.Resource_ soda.tiles.fairness.tool.TileMessage soda.tiles.fairness.tool.TileMessage_ soda.tiles.fairness.tool.TileMessageBuilder diff --git a/tiles/src/test/scala/soda/tiles/fairness/tile/ResourceAllocationScenarioExample.soda b/tiles/src/test/scala/soda/tiles/fairness/tile/ResourceAllocationScenarioExample.soda index 6fe7fea..f839b6b 100644 --- a/tiles/src/test/scala/soda/tiles/fairness/tile/ResourceAllocationScenarioExample.soda +++ b/tiles/src/test/scala/soda/tiles/fairness/tile/ResourceAllocationScenarioExample.soda @@ -9,17 +9,17 @@ class ResourceAllocationScenarioExample measure_sum (a : Measure) (b : Measure) : Measure = Measure_ (a .value + b .value) - resource0 = Resource_ ("small box - 0.1 m") + resource0 = "small box - 0.1 m" - resource1 = Resource_ ("medium box - 0.2 m") + resource1 = "medium box - 0.2 m" - resource2 = Resource_ ("large box - 0.3 m") + resource2 = "large box - 0.3 m" - actor0 = Actor_ ("Anna A") + actor0 = "Anna A" - actor1 = Actor_ ("Bob B") + actor1 = "Bob B" - actor2 = Actor_ ("Charlie C") + actor2 = "Charlie C" actor_need_map : Map [Actor] [Measure] = Seq ( Tuple2 [Actor] [Measure] (actor0 , Measure_ (30) ) , @@ -39,7 +39,7 @@ class ResourceAllocationScenarioExample resource_height (resource : Resource) : Measure = resource_height_map .getOrElse (resource , Measure_ (-1) ) - context = Context_ () + context = "context" outcome0 : Outcome = Outcome_ ( diff --git a/tiles/src/test/scala/soda/tiles/fairness/tile/ScoringScenarioExample.soda b/tiles/src/test/scala/soda/tiles/fairness/tile/ScoringScenarioExample.soda index 20de56d..8bda98a 100644 --- a/tiles/src/test/scala/soda/tiles/fairness/tile/ScoringScenarioExample.soda +++ b/tiles/src/test/scala/soda/tiles/fairness/tile/ScoringScenarioExample.soda @@ -8,11 +8,11 @@ class ScoringScenarioExample "Alice", "Benjamin", "Charlotte", "Daniel", "Emily", "Fiona", "George", "Hannah", "Isaac", "James", "Kevin", "Lily", "Matthew", "Natalie", "Olivia", "Quinn", "Peter", "Rachel", "Sarah", "Timothy", "Ursula", "Victoria", "William", "Xavier", "Yasmine", "Zachary" - ) .map (lambda name --> Actor_ (name) ) + ) - _resource_zero : Resource = Resource_ ("0") + _resource_zero : Resource = "0" - _resource_one : Resource = Resource_ ("1") + _resource_one : Resource = "1" _measure_zero : Measure = Measure_ (0) @@ -133,7 +133,7 @@ class ScoringScenarioExample then _measure_zero else _measure_one - context = Context_ () + context = "context" initial_unbiased : TileMessage [Boolean] = TileMessageBuilder_ () .build (context) (unbiased_outcome) (true)