Ejemplo n.º 1
0
    public static void RunValidationC() {
      // Run the example in section 3.4.3 of Cousot and Halbwachs backwards, that is, from
      // from to constraints.
      IVariable/*!*/ dim1 = new TestVariable("X");
      IVariable/*!*/ dim2 = new TestVariable("Y");
      IVariable/*!*/ dim3 = new TestVariable("Z");
      Contract.Assert(dim1 != null);
      Contract.Assert(dim2 != null);
      Contract.Assert(dim3 != null);

      FrameElement s0 = new FrameElement();
      s0.AddCoordinate(dim1, Rational.ONE);
      s0.AddCoordinate(dim2, Rational.FromInts(1, 2));
      s0.AddCoordinate(dim3, Rational.FromInts(-1, 2));

      FrameElement s1 = new FrameElement();
      s1.AddCoordinate(dim1, Rational.ONE);
      s1.AddCoordinate(dim2, Rational.FromInts(-1, 2));
      s1.AddCoordinate(dim3, Rational.FromInts(1, 2));

      FrameElement s2 = new FrameElement();
      s2.AddCoordinate(dim1, Rational.FromInt(3));
      s2.AddCoordinate(dim2, Rational.FromInts(-3, 2));
      s2.AddCoordinate(dim3, Rational.FromInts(3, 2));

      FrameElement r0 = new FrameElement();
      r0.AddCoordinate(dim1, Rational.ONE);
      r0.AddCoordinate(dim2, Rational.FromInts(1, 2));
      r0.AddCoordinate(dim3, Rational.FromInts(-1, 2));

      FrameElement r1 = new FrameElement();
      r1.AddCoordinate(dim1, Rational.ONE);
      r1.AddCoordinate(dim2, Rational.ZERO);
      r1.AddCoordinate(dim3, Rational.ZERO);

      FrameElement d0 = new FrameElement();
      d0.AddCoordinate(dim1, Rational.ZERO);
      d0.AddCoordinate(dim2, Rational.ONE);
      d0.AddCoordinate(dim3, Rational.ONE);

      LinearConstraintSystem lcs = new LinearConstraintSystem(s0);
      lcs.Dump();

      lcs.AddVertex(s1);
      lcs.Dump();

      lcs.AddVertex(s2);
      lcs.Dump();

      lcs.AddRay(r0);
      lcs.Dump();

      lcs.AddRay(r1);
      lcs.Dump();

      lcs.AddLine(d0);
      lcs.Dump();

      lcs.SimplifyConstraints();
      lcs.Dump();

#if LATER
      lcs.GenerateFrameFromConstraints(); // should give us back the original frame...
#endif
    }
Ejemplo n.º 2
0
    public static void RunValidationA() {
      IVariable/*!*/ dim1 = new TestVariable("X");
      IVariable/*!*/ dim2 = new TestVariable("Y");
      IVariable/*!*/ dim3 = new TestVariable("Z");
      Contract.Assert(dim1 != null);
      Contract.Assert(dim2 != null);
      Contract.Assert(dim3 != null);

      FrameElement s1 = new FrameElement();
      s1.AddCoordinate(dim1, Rational.ONE);
      s1.AddCoordinate(dim2, Rational.MINUS_ONE);
      s1.AddCoordinate(dim3, Rational.ZERO);
      FrameElement s2 = new FrameElement();
      s2.AddCoordinate(dim1, Rational.MINUS_ONE);
      s2.AddCoordinate(dim2, Rational.ONE);
      s2.AddCoordinate(dim3, Rational.ZERO);
      FrameElement r1 = new FrameElement();
      r1.AddCoordinate(dim1, Rational.ZERO);
      r1.AddCoordinate(dim2, Rational.ZERO);
      r1.AddCoordinate(dim3, Rational.ONE);
      FrameElement d1 = new FrameElement();
      d1.AddCoordinate(dim1, Rational.ONE);
      d1.AddCoordinate(dim2, Rational.ONE);
      d1.AddCoordinate(dim3, Rational.ZERO);

      // create lcs from frame -- cf. Cousot/Halbwachs 1978, section 3.3.1.1
      LinearConstraintSystem lcs = new LinearConstraintSystem(s1);
      lcs.Dump();

      lcs.AddVertex(s2);
      lcs.Dump();

      lcs.AddRay(r1);
      lcs.Dump();

      lcs.AddLine(d1);
      lcs.Dump();

      lcs.SimplifyConstraints();
      lcs.Dump();

#if LATER
      lcs.GenerateFrameFromConstraints(); // should give us back the original frame...
#endif
      Console.WriteLine("IsSubset? {0}", lcs.IsSubset(lcs.Clone()));
      lcs.Dump();
    }