This GitLab instance reached the end of its service life. It won't be possible to create new users or projects.

Please read the deprecation notice for more information concerning the deprecation timeline

Visit migration.git.tu-berlin.de (internal network only) to import your old projects to the new GitLab platform 📥

TransitionSystem.scala 1.29 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
package de.bbisping.coupledsim.ts

import de.bbisping.coupledsim.util.LabeledRelation

case class TransitionSystem[S, A, L](
    val step: LabeledRelation[S, A],
    val nodeLabeling: Map[S, L]) {
  
  def post(s: S, a: A): Set[S] =
    step.values(s, a)
    
  def post(ss: Set[S], a: A): Set[S] =
    for { s <- ss; sp <- post(s, a) } yield sp
    
  def post(ss: Set[S]): Map[A, Set[S]] = {
    val en = for { s <- ss; a <- enabled(s) } yield a
    val p = for { a <- en } yield (a, post(ss, a))
    p.toMap
  }
  
  def post(s: S, aa: Set[A]): Set[S] =
    for { a <- aa; sp <- post(s, a) } yield sp
    
  def post(s: S) =
    step.rep.getOrElse(s, Map())
    
  def pre(s: S, a: A): Set[S] =
    step.valuesInverse(s, a)
    
  def pre(s: S): Map[A, Set[S]] =
    step.inverseRep.getOrElse(s, Map())
  
  def pre(ss: Set[S], a: A): Set[S] =
    for { s <- ss; sp <- pre(s, a) } yield sp
    
  def pre(ss: Set[S]): Map[A, Set[S]] = {
    for { s <- ss; sp <- pre(s) toList } yield sp
  }.groupBy(_._1).mapValues(_.flatMap(_._2))
  
  def enabled(s: S) = post(s).keySet
  
  def reachingActions(s: S) = pre(s).keySet
  
  val nodes = nodeLabeling.keySet
  
  val nodesByLabel =
    nodeLabeling.groupBy(_._2).mapValues(_.keySet)
    
  val actions = step.labels
    
  def isFreshNode(s: S) = !nodes.contains(s)
}