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 📥

CoupledSimulations.scala 1.85 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
package de.bbisping.coupledsim.algo

import utest._
import de.bbisping.coupledsim.tool.control.StructureOperation
import de.bbisping.coupledsim.algo.cs.SchematicCoupledSimilarity
import de.bbisping.coupledsim.tool.model.NodeID
import de.bbisping.coupledsim.util.Relation

/**
 * Tests that all coupled simulation algorithms compute the same maximal coupled simulations
 * like SchematicCoupledSimilarity for the whole TestSample set.
 */

object CoupledSimulations extends TestSuite {
  
  AlgorithmLogging.loggingActive = false
  
  val cannonicalCSimulations = for {
    (slug, system) <- TestSamples.samples
    val rel = new SchematicCoupledSimilarity(system).compute()
  } yield (slug, system, rel)
  
  val simulationAlgos = List[StructureOperation.StructureRelationAnalyzer](
      new StructureOperation.FixedPointCoupledSimilarityAnalyzer,
      new StructureOperation.BasicSACoupledSimilarityAnalyzer,
      new StructureOperation.GameCoupledSimilarityAnalyzer,
      new StructureOperation.GameCoupledSimilarityPlainAnalyzer
  )
  
  def testAlgo()(implicit path: utest.framework.TestPath) = {
    val algoSlug = path.value.last
    for {
      algo <- simulationAlgos find (_.slug == algoSlug)
      (slug, system, cannonicalRel) <- cannonicalCSimulations
    } {
      val (rel, _) = algo.analyze(system)
      println(slug)
      val relDiffCannonical = rel filter { case (s1: NodeID, s2: NodeID) => !cannonicalRel(s1, s2) }
      assert(relDiffCannonical == Relation[NodeID]() )
      val cannonicalDiffRel = cannonicalRel filter { case (s1: NodeID, s2: NodeID) => !rel(s1, s2) }
      assert(cannonicalDiffRel == Relation[NodeID]() )
    }
  }
  
  val tests = Tests {
    "fixed-point-coupled-similarity" - testAlgo()
    //"basic-sa-coupled-similarity" - testAlgo() // broken!
    "game-coupled-similarity" - testAlgo()
    "game-coupled-similarity-plain" - testAlgo()
  }
}