Skip to content

Commit

Permalink
Customizable agent generation params
Browse files Browse the repository at this point in the history
  • Loading branch information
IDoCodingStuffs committed Jun 21, 2019
1 parent 0aeb986 commit 4a1d3a4
Show file tree
Hide file tree
Showing 32 changed files with 81 additions and 35,704 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
*.xslt
project
target
data
1 change: 0 additions & 1 deletion conf/app.conf

This file was deleted.

4 changes: 4 additions & 0 deletions conf/application.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
numberGroupsSimulated = 10000
preferenceGenerators = "Uniform;Uniform;Uniform;Uniform"
weightsGenerators = "Uniform;Uniform;Uniform;Uniform"
decisionModels = "WeightedRoundup(0.5,0.5);WeightedRoundup(0.5,0.5);WeightedRoundup(0.5,0.5)"
Binary file not shown.
Binary file not shown.
Empty file.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ class DataAggregatorActor extends Actor with ActorLogging {
// .averagedPreferenceKnowledge

memberStats.show(5, truncate = false)
groupDecisionStats.show(false)

groupDecisionStats.coalesce(1).write.json(s"./data/decision_composition/$jobRunAtDateTime/yes_vote_counts")
memberStats.write.json(s"./data/member_behavior/$jobRunAtDateTime/full")
groupDecisionStats.coalesce(1).write.json(s"./data/decision_composition/$jobRunAtDateTime/yes_vote_counts")
memberStats.write.json(s"./data/member_behavior/$jobRunAtDateTime/full")

}
}
69 changes: 57 additions & 12 deletions src/main/scala/net/codingstuffs/abilene/model/Abilene.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package net.codingstuffs.abilene.model

import java.time.Duration

import akka.actor.{ActorRef, ActorSystem, PoisonPill}
import akka.actor.{ActorRef, ActorSystem}
import net.codingstuffs.abilene.analytics.DataAggregatorActor
import net.codingstuffs.abilene.analytics.DataAggregatorActor.CreateDump

Expand All @@ -11,11 +9,11 @@ import akka.actor._
import akka.pattern.ask
import akka.util.Timeout
import com.typesafe.config.ConfigFactory
import net.codingstuffs.abilene.model.decision_making.generators.random.Uniform
import net.codingstuffs.abilene.model.decision_making.models.ArithmeticRoundup.SelfishRoundup
import net.codingstuffs.abilene.model.decision_making.generators.random.{Beta, Discrete, FoldedGaussian, Uniform}
import net.codingstuffs.abilene.model.decision_making.models.ArithmeticRoundup.{EgalitarianRoundup, SelfishRoundup, WeightedRoundup}
import net.codingstuffs.abilene.model.decision_making.models.Models.DecisionMakingModel

import scala.concurrent.duration
import scala.concurrent.duration.{Duration, FiniteDuration}
import scala.concurrent.duration.FiniteDuration

object Abilene extends App {

Expand All @@ -25,6 +23,50 @@ object Abilene extends App {

val extraIterations: Int = config.getInt("numberGroupsSimulated")

//!TODO: Refactor this plz future me thx
val decisionModels: Seq[DecisionMakingModel] = {
config.getString("decisionModels").split(";")
.map({
case "SelfishRoundup" => SelfishRoundup
case "EgalitarianRoundup" => EgalitarianRoundup
case "WeightedRoundup" => SelfishRoundup
case sasScale: String if sasScale.startsWith("WeightedRoundup(") =>
WeightedRoundup(
"""(?<=\()(.*?)(?=\))""".r.findFirstIn(sasScale).get.split(",")(0).toDouble,
"""(?<=\()(.*?)(?=\))""".r.findFirstIn(sasScale).get.split(",")(1).toDouble
)
})
}
val preferenceGenerators: Seq[Random] = {
config.getString("preferenceGenerators").split(";")
.map({
case "Uniform" => Uniform.GENERATOR
case discrete: String if discrete.startsWith("Discrete") =>
Discrete.GENERATOR("""(?<=\()(.*?)(?=\))""".r.findFirstIn(discrete).get.split(",").map(_.toDouble).toSeq)
case beta: String if beta.startsWith("Beta") =>
Beta.GENERATOR(
"""(?<=\()(.*?)(?=\))""".r.findFirstIn(beta).get.split(",")(0).toDouble,
"""(?<=\()(.*?)(?=\))""".r.findFirstIn(beta).get.split(",")(1).toDouble)
case gaussian: String if gaussian.startsWith("FoldedGaussian") =>
FoldedGaussian.GENERATOR(
"""(?<=\()(.*?)(?=\))""".r.findFirstIn(gaussian).get.toDouble)
}).toSeq
}
val weightsGenerators: Seq[Random] = {
config.getString("preferenceGenerators").split(";")
.map({
case "Uniform" => Uniform.GENERATOR
case discrete: String if discrete.startsWith("Discrete") =>
Discrete.GENERATOR("""(?<=\()(.*?)(?=\))""".r.findFirstIn(discrete).get.split(",").map(_.toDouble).toSeq)
case beta: String if beta.startsWith("Beta") =>
Beta.GENERATOR(
"""(?<=\()(.*?)(?=\))""".r.findFirstIn(beta).get.split(",")(0).toDouble,
"""(?<=\()(.*?)(?=\))""".r.findFirstIn(beta).get.split(",")(0).toDouble)
case gaussian: String if gaussian.startsWith("FoldedGaussian") =>
FoldedGaussian.GENERATOR(
"""(?<=\()(.*?)(?=\))""".r.findFirstIn(gaussian).get.toDouble)
}).toSeq
}

val system: ActorSystem = ActorSystem("Abilene0")
val dataDumpGenerator = system.actorOf(DataAggregatorActor.props, "dataDumper")
Expand All @@ -41,16 +83,19 @@ object Abilene extends App {
group = system.actorOf(Group.props(groupMembers, dataDumpGenerator), s"$groupId---group")

father = system.actorOf(
Member.props(group, SelfishRoundup, Uniform.GENERATOR),
Member.props(group, decisionModels.head, (preferenceGenerators.head, weightsGenerators.head)),
s"$groupId@@@father")
mother = system.actorOf(
Member.props(group, SelfishRoundup, Uniform.GENERATOR),
Member.props(group, decisionModels(1), (preferenceGenerators(1), weightsGenerators(1))),
s"$groupId@@@mother")
wife = system.actorOf(
Member.props(group, SelfishRoundup, Uniform.GENERATOR), s"$groupId@@@wife")
husband = system.actorOf(Member.props(group, SelfishRoundup, Uniform.GENERATOR), s"$groupId@@@husband")
Member.props(group, decisionModels(2), (preferenceGenerators(2), weightsGenerators(2))),
s"$groupId@@@wife")
husband = system.actorOf(
Member.props(group, decisionModels(3), (preferenceGenerators(3), weightsGenerators(3))),
s"$groupId@@@husband")

father ! Declare
father ? Declare
})
}
finally {
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/net/codingstuffs/abilene/model/Member.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import net.codingstuffs.abilene.model.decision_making.generators.random.{Beta, D
import scala.util.Random

object Member {
def props(group: ActorRef, decisionModel: DecisionMakingModel, randomGenerator: Random): Props =
def props(group: ActorRef, decisionModel: DecisionMakingModel, randomGenerator: (Random, Random)): Props =
Props(new Member(group, decisionModel, randomGenerator))

final case class ReceiveDecision(member: String, decision: Boolean)
Expand All @@ -20,14 +20,14 @@ object Member {

}

class Member(group: ActorRef, decisionModel: DecisionMakingModel, randomGenerator: Random)
class Member(group: ActorRef, decisionModel: DecisionMakingModel, randomGenerators: (Random, Random))
extends Actor with ActorLogging{

import Member._

private val name = self.path.name.split("@@@")(1)
//!TODO: Make this specifiable
private val agentParamGenerator: AgentParamGenerator = new AgentParamGenerator(randomGenerator)
private val agentParamGenerator: AgentParamGenerator = new AgentParamGenerator(randomGenerators)

agentParamGenerator.self = name
//!TODO: Generalize this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ object AgentParamGenerator {

}

class AgentParamGenerator(preferenceGenerator: Random, weightsGenerator: Random) {
class AgentParamGenerator(randomGenerators: (Random, Random)) {

implicit var self: String = _
implicit var memberNames: Set[String] = _

val preferenceGenerator = randomGenerators._1
val weightsGenerator = randomGenerators._2


def getSelfParams(name: String): (String, Double, Double) =
(self, preferenceGenerator.nextDouble(), weightsGenerator.nextDouble())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ import org.apache.commons.math3.distribution.BetaDistribution
import scala.util.Random

object Beta {
final val GENERATOR = new Beta
def GENERATOR(alpha: Double, beta: Double) = new Beta(alpha, beta)
}

class Beta extends Random {
override def nextDouble(): Double =
new BetaDistribution(2, 2).inverseCumulativeProbability(super.nextDouble)

def nextDouble(alpha: Double, beta: Double): Double =
class Beta(alpha: Double, beta: Double) extends Random {
override def nextDouble: Double =
new BetaDistribution(alpha, beta).inverseCumulativeProbability(super.nextDouble)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package net.codingstuffs.abilene.model.decision_making.generators.random
import scala.util.Random

object Discrete {
final val GENERATOR = new Discrete(0, 0.25, 0.5, 0.75, 1)
final def GENERATOR(values: Seq[Double]) = new Discrete(values)
}

class Discrete(values: Double*) extends Random{
class Discrete(values: Seq[Double]) extends Random{
override def nextDouble: Double = shuffle(values).head
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ package net.codingstuffs.abilene.model.decision_making.generators.random
import scala.util.Random

object FoldedGaussian {
final val GENERATOR = new FoldedGaussian
final def GENERATOR(mean: Double) = new FoldedGaussian(mean)
}

class FoldedGaussian extends Random {
override def nextDouble: Double = math.abs(super.nextGaussian)

def nextDouble(mean: Double): Double = math.abs(nextDouble + mean)
class FoldedGaussian(mean: Double) extends Random {
override def nextDouble: Double = math.abs(super.nextGaussian) + mean
}

0 comments on commit 4a1d3a4

Please sign in to comment.