Demo entry 2530072

blah

   

Submitted by anonymous on Aug 27, 2015 at 11:29
Language: Scala. Code size: 6.9 kB.

package arbre

/**
  * @author mdavy
  */
import scala.collection.immutable.{HashSet, HashMap}

class Environment {

  import scala.collection.mutable.HashMap
  var listInputs: List[StreamExpr] = Nil
  var listOutput: List[StreamExpr] = Nil
  val mapUp: HashMap[BoolVar,BoolExpr] = HashMap.empty
  val realMap: HashMap[RealVar, RealExpr] = HashMap.empty
  val boolMap: HashMap[BoolVar, BoolExpr] = HashMap.empty
  var count: Int = 0
  val mapIntegDeriv: HashMap[RealVar, RealVar] = HashMap.empty
  var listOfInteg: List[RealVar] = Nil
  val mapOfTempoReal: HashMap[RealVar,RealExpr] = HashMap.empty
  val mapOfTempoBool: HashMap[BoolVar,BoolExpr] = HashMap.empty
  var listVarDisc: List[RealVar] = Nil
  var listVarBool: List[BoolVar] = Nil
  
  def add(v: RealVar, d: RealExpr) = {
    realMap.update(v, d)
  }

  def add(v: BoolVar, d: BoolExpr) = {
    boolMap.update(v, d)
  }
  def addUp(v: BoolVar, d: BoolExpr) ={
    mapUp.update(v,d)
  }
  
  def addDisc(v: RealVar) = {
    listVarDisc = v :: listVarDisc
  }
  
  def addDiscBool(v: BoolVar) = {
    listVarBool = v :: listVarBool
  }
  
  def get(v: BoolVar): Option[BoolExpr] = boolMap.get(v)

  def get(v: RealVar): Option[RealExpr] = realMap.get(v)

  def getCount(): Int = count

  def setCount(b: Int) = {
    count = b
  }

  def add(i: RealVar, d: RealVar) = {
    mapIntegDeriv.update(i, d)
  }
  def addInteg(i: RealVar) = {
    listOfInteg = i :: listOfInteg
  }
}

class DerivEnv {
  //Nouvelle structure pour stocker les real(deriv) avec leurs expressions

  import scala.collection.immutable.SortedMap

  var derivMap: List[(RealVar, Map[Set[BoolExpr], RealExpr])] = Nil
  var RealPreMap: List[(RealVar, Map[Set[BoolExpr], RealExpr])] = Nil
  var PreMap: List[(BoolVar, Map[Set[BoolExpr], BoolExpr])] = Nil
  
  def add(v: RealVar, d: Map[Set[BoolExpr], RealExpr]) = {
    derivMap = (v,d) :: derivMap
  }
  
  def addRealPre(v: RealVar, d: Map[Set[BoolExpr], RealExpr]) = {
    RealPreMap = (v,d) :: RealPreMap
  }
  def addPre(v: BoolVar, d: Map[Set[BoolExpr], BoolExpr]) = {
    PreMap = (v,d) :: PreMap
  }
}

sealed abstract trait StreamExpr

sealed abstract trait BoolExpr extends StreamExpr

/** Expression with a unary operator. */
case class BoolExprI( op: BoolOpI, kid1: BoolExpr ) extends BoolExpr {
  def repr = toString
}

/** Expression with a binary operator. */
case class BoolExprII( op: BoolOpII, kid1: BoolExpr, kid2: BoolExpr ) extends BoolExpr {
  def repr = toString
}

/** Expression with a binary operator. */
case class BoolRelExprII( op: BoolRelOpII, kid1: RealExpr, kid2: RealExpr ) extends BoolExpr {
  def repr = toString
}


//    /** Expression with an n-ary operator. */
//    case class BoolExprN( op: BoolOpN, kid1: List[StreamExpr] ) extends BoolExpr {
//      def repr = toString
//    }



sealed abstract trait Operator
sealed abstract trait BoolOp extends Operator
sealed abstract trait BoolRelOp extends Operator

/** Base trait for all unary operators. */
sealed abstract trait BoolOpI extends BoolOp {
  def apply( kid1: BoolExpr ) = BoolExprI( this, kid1 )
  def unapply( e: BoolExprI ) = if (e.op == this) Some( e.kid1 ) else None
}

/** Base trait for all binary operators. */
sealed abstract trait BoolOpII extends BoolOp {
  def apply( kid1: BoolExpr, kid2: BoolExpr ) = BoolExprII( this, kid1, kid2 )
  def unapply( e: BoolExprII ) = if (e.op == this) Some( (e.kid1, e.kid2) ) else None
}

/** Base trait for all binary operators. */
sealed abstract trait BoolRelOpII extends BoolRelOp {
  def apply( kid1: RealExpr, kid2: RealExpr ) = BoolRelExprII( this, kid1, kid2 )
  def unapply( e: BoolRelExprII ) = if (e.op == this) Some( (e.kid1, e.kid2) ) else None
}

/** Base trait for BoolExpr*/

case class BoolConst(c: Boolean) extends BoolExpr
case class BoolVar(name: String) extends BoolExpr
case class BoolITE(c: BoolExpr, l: BoolExpr, r: BoolExpr) extends BoolExpr

/** Boolean n-ary operator */
//case class Sharp(l: List[BoolExpr]) extends  BoolExpr

/** Boolean binary operator */
case object And extends BoolOpII
case object Or extends BoolOpII
case object Gt extends BoolRelOpII
case object Ge extends BoolRelOpII
case object Eq extends BoolRelOpII
case object Lt extends BoolRelOpII
case object Le extends BoolRelOpII
case object Neq extends BoolRelOpII
case object Xor extends BoolOpII
case object Impl extends BoolOpII
case object Equiv extends BoolOpII
case object InitArrowBool extends BoolOpII
case object FbyBool extends BoolOpII


/** Boolean unary operator */
case object Not extends BoolOpI
case object PreBool extends BoolOpI

sealed abstract trait RealExpr extends StreamExpr

/** Expression with a unary operator. */
case class RealExprI( op: RealOpI, kid1: RealExpr ) extends RealExpr {
  def repr = toString
}

/** Expression with a binary operator. */
case class RealExprII( op: RealOpII, kid1: RealExpr, kid2: RealExpr ) extends RealExpr {
  def repr = toString
}

/** Expression with a ternary operator. */
case class RealITE( kid1: BoolExpr, kid2: RealExpr, kid3: RealExpr ) extends RealExpr {
  def repr = toString
}

///** Expression with an n-ary operator. */
//case class RealExprN( op: RealOpN, kid1: List[RealExpr] ) extends RealExpr {
//  def repr = toString
//}

sealed abstract trait RealOp extends Operator
/** Base trait for all unary operators. */
sealed abstract trait RealOpI extends RealOp {
  def apply( kid1: RealExpr ) = RealExprI( this, kid1 )
  def unapply( e: RealExprI ) = if (e.op == this) Some( e.kid1 ) else None
}

/** Base trait for all binary RealOps. */
sealed abstract trait RealOpII extends RealOp {
  def apply( kid1: RealExpr, kid2: RealExpr ) = RealExprII( this, kid1, kid2 )
  def unapply( e: RealExprII ) = if (e.op == this) Some( (e.kid1, e.kid2) ) else None
}

///** Base trait for all n-ary RealOps. */
//sealed abstract trait RealOpN extends RealOp {
//  def apply( kid1: List[RealExpr] ) = RealExprN( this, kid1 )
//  def unapply( e: RealExprN ) = if (e.op == this) Some( e.kid1 ) else None
//}



/** Base trait for RealExpr*/

case class RealConst(c: String) extends RealExpr
case class RealVar(name: String) extends RealExpr
case class Integr(deriv: RealExpr) extends RealExpr


/** Real binary operators */
case object Add extends RealOpII
case object Sub extends RealOpII
case object FbyReal extends RealOpII
case object Mult extends RealOpII
case object Div extends RealOpII
case object InitArrowReal extends RealOpII


/** Real unary operator */
case object Minus extends RealOpI
case object Last extends RealOpI
case class MathOp( s: String ) extends RealOpI
case object RealPre extends RealOpI

sealed abstract trait TupleInterval
case class Interval(inf: RealExpr,sup: RealExpr) extends TupleInterval

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).