 @testable import SwiftFusion
 
 /// A factor on two discrete labels evaluation the transition probability
-struct DiscreteTransitionFactor : NewFactor {  
+struct DiscreteTransitionFactor : Factor {
   typealias Variables = Tuple2<Int, Int>
   
   /// The IDs of the variables adjacent to this factor.

    let flipAndOptimize = {(x:VariableAssignments) -> VariableAssignments in
      let labelVars = x.storage[ObjectIdentifier(Int.self)]
      let positionVars = x.storage[ObjectIdentifier(Pose2.self)]

      // Randomly change one label.
      let i = Int.random(in: 0..<labelVars!.count)
      let id = TypedID<Int, Int>(i)

      Pose2(1, 0, -.pi / 4) // turn right
    ]
    
    var graph = FactorGraph()
    graph.store(PriorFactor2(x1, z1)) // prior
    graph.store(PriorFactor2(x1, z1))
    graph.store(PriorFactor2(x2, z2))
    graph.store(PriorFactor2(x3, z3))
    graph.store(SwitchingBetweenFactor2(x1, q1, x2, movements))
    graph.store(SwitchingBetweenFactor2(x2, q2, x3, movements))
    graph.store(DiscreteTransitionFactor(q1, q2, labelCount, transitionMatrix))
    
    return (graph, variables)
  }
  
  func printLabels(_ variables : VariableAssignments) {
    print(variables[TypedID<Int, Int>(0)])
    print(variables[TypedID<Int, Int>(1)])
  }
  
  /// Tracking switching from Figure 2.b
  func testSwitchingExample() {
    // create a factor graph
    var (graph, variables) = createSwitchingFactorGraph()
    _ = graph as FactorGraph
    _ = variables as VariableAssignments
    
    // check number of factor types
