Skip to content

Commit

Permalink
Simplify Actor, Resource, and Context types
Browse files Browse the repository at this point in the history
  • Loading branch information
julianmendez committed Feb 18, 2024
1 parent edaca52 commit 074b5e8
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 114 deletions.
36 changes: 4 additions & 32 deletions tiles/src/main/scala/soda/tiles/fairness/tool/Entity.soda
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -86,9 +64,3 @@ class Outcome
end


class Context

abstract

end

58 changes: 4 additions & 54 deletions tiles/src/main/scala/soda/tiles/fairness/tool/Package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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} -
Expand Down
25 changes: 11 additions & 14 deletions tiles/src/test/scala/soda/tiles/fairness/tile/Package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) ) ,
Expand All @@ -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_ (
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions tiles/src/test/scala/soda/tiles/fairness/tile/Package.soda
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) ) ,
Expand All @@ -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_ (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 074b5e8

Please sign in to comment.