Ejemplo n.º 1
0
    public void Run()
    {
        using (Context ctx = new Context())
        {
            Console.WriteLine("Simplify");
            Symbol[] sp = ctx.SimplifyParameterDescriptions.Names;
            foreach (var s in sp)
            {
                Console.WriteLine("{0}", s);
            }

            Console.WriteLine("Fixedpoint");
            Fixedpoint fp = ctx.MkFixedpoint();
            sp = fp.ParameterDescriptions.Names;
            foreach (var s in sp)
            {
                Console.WriteLine("{0}", s);
            }
        }
    }
Ejemplo n.º 2
0
    public void Run()
    {
        using (Context ctx = new Context())
        {
            this.ctx = ctx;
            ctx.UpdateParamValue("DL_GENERATE_EXPLANATIONS", "true");

            red_car = new Car(false, 2, 2, 3, "red");
            cars    = new Car[] {
                new Car(true, 0, 3, 0, "yellow"),
                new Car(false, 3, 3, 0, "blue"),
                new Car(false, 5, 2, 0, "brown"),
                new Car(false, 0, 2, 1, "lgreen"),
                new Car(true, 1, 2, 1, "light blue"),
                new Car(true, 2, 2, 1, "pink"),
                new Car(true, 2, 2, 4, "dark green"),
                red_car,
                new Car(true, 3, 2, 3, "purple"),
                new Car(false, 5, 2, 3, "light yellow"),
                new Car(true, 4, 2, 0, "orange"),
                new Car(false, 4, 2, 4, "black"),
                new Car(true, 5, 3, 1, "light purple")
            };

            this.num_cars = cars.Length;
            this.B        = ctx.MkBoolSort();
            this.bv3      = ctx.MkBitVecSort(3);
            List <Sort> domain = new List <Sort>();
            foreach (var c in cars)
            {
                domain.Add(bv3);
            }
            this.state = ctx.MkFuncDecl("state", domain.ToArray(), B);
            this.fp    = ctx.MkFixedpoint();
            this.fp.RegisterRelation(state);


            // Initial state:

            Expr[] args = new Expr[num_cars];
            for (int i = 0; i < num_cars; ++i)
            {
                args[i] = num(cars[i].start);
            }
            fp.AddRule((BoolExpr)state[args]);

            // Transitions:
            for (int pos = 0; pos < num_cars; ++pos)
            {
                Car car = cars[pos];
                for (int i = 0; i < dimension; ++i)
                {
                    if (car.is_vertical)
                    {
                        move_down(i, pos, car);
                        move_up(i, pos, car);
                    }
                    else
                    {
                        move_left(i, pos, car);
                        move_right(i, pos, car);
                    }
                }
            }

            // Print the current context:
            Console.WriteLine("{0}", fp);

            // Prepare the query:
            for (int i = 0; i < num_cars; ++i)
            {
                args[i] = (cars[i] == red_car) ? num(4) : bound(i);
            }
            BoolExpr goal = (BoolExpr)state[args];
            fp.Query(goal);

            // Extract a path:
            get_instructions(fp.GetAnswer());
        }
    }