Exemplo n.º 1
0
        protected void buildFruitsSet()
        {
            product            = new DiscreteDimension("Product", "Product being offered");
            fruits             = new DiscreteSet(product, "Fruits");
            product.DefaultSet = fruits;

            apple        = new Fruit(product, "Apple");
            pear         = new Fruit(product, "Pear");
            tomato       = new Fruit(product, "Tomato");
            blueberry    = new Fruit(product, "Blueberry");
            blackberry   = new Fruit(product, "Blackberry");
            blackCurrant = new Fruit(product, "Black-currant");
            strawberry   = new Fruit(product, "Strawberry");
            lemon        = new Fruit(product, "Lemon");
            melon        = new Fruit(product, "Melon");
            broccoli     = new Fruit(product, "Broccoli");

            fruits.AddMember(apple, (double)trackBar1.Value / 100);
            fruits.AddMember(pear, (double)trackBar2.Value / 100);
            fruits.AddMember(lemon, (double)trackBar3.Value / 100);
            fruits.AddMember(melon, (double)trackBar4.Value / 100);
            fruits.AddMember(tomato, (double)trackBar5.Value / 100);
            fruits.AddMember(blackCurrant, (double)trackBar6.Value / 100);
            fruits.AddMember(blackberry, (double)trackBar7.Value / 100);
            fruits.AddMember(strawberry, (double)trackBar8.Value / 100);
            fruits.AddMember(blueberry, (double)trackBar9.Value / 100);
            fruits.AddMember(broccoli, (double)trackBar10.Value / 100);

            RelationImage imgFruits = new RelationImage(fruits);
            Bitmap        bmpFruits = new Bitmap(pictureBoxFruits.Width, pictureBoxFruits.Height);

            imgFruits.DrawImage(Graphics.FromImage(bmpFruits));
            pictureBoxFruits.Image = bmpFruits;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="Constraint"/> class.
 /// </summary>
 /// <param name="collection">The collection.</param>
 /// <param name="modulo">The modulo.</param>
 public ConnectedLineConstraint(TrainLine line1, TrainLine line2, int modulo)
     : base(
         new int[] {
     PeriodUtil.normalizeTime(line2.ConnectedLineShift.ToMinutes() - line1.ConnectedLineShift.ToMinutes(), modulo)
 },
         modulo
         )
 {
     setConnectedConstraintDefaultValues();
     TrainLine1      = line1;
     TrainLine2      = line2;
     ConstantMember1 = line1.ConnectedLineShift.ToMinutes();
     ConstantMember2 = line2.ConnectedLineShift.ToMinutes();
     // create min factor for single set
     DiscreteSet.createMinimizationFactor(0);
 }
        /// <summary>
        /// Reverses the constraint (as multiply by -1).
        /// </summary>
        public void reverseConstraint()
        {
            int tempInt;

            // swap indices in matrices
            tempInt = index1;
            index1  = index2;
            index2  = tempInt;

            // swap constant matrix - related to train lines
            tempInt         = constantMember1;
            constantMember1 = constantMember2;
            constantMember2 = tempInt;

            TrainLine tempTL;

            // swap train lines
            tempTL     = trainLine1;
            trainLine1 = trainLine2;
            trainLine2 = tempTL;

            // reverse DiscreteSet (minimization solutionFactor reverse included)
            DiscreteSet.Reverse();
        }
        public static void TestCase()
        {
            DiscreteSet         s       = new DiscreteSet();
            DiscreteElement     peuh    = new DiscreteElement(5, 3);
            DiscreteElement     peuh2   = new DiscreteElement(5, 9);
            StringReferenceList refList = new StringReferenceList("Aka", "Bea", "Coq", "Dad", "Elf");

            Console.WriteLine("\n\n" +
                              "+--------------------------------------------------------------------+\n" +
                              "|                         DiscreteSet Tests                          |\n" +
                              "+--------------------------------------------------------------------+"
                              );
            Console.WriteLine(refList);
            Console.WriteLine("----------------------------------------------------------------------");
            Console.WriteLine("Empty set:           {0}", s.ToString(refList));
            Console.WriteLine("Adding the element   {0}", peuh.ToString(refList));
            s.Add(peuh);
            Console.WriteLine("Resulting set:       {0}", s.ToString(refList));
            Console.WriteLine("Adding the element   {0}", peuh.ToString(refList));
            s.Add(peuh);
            Console.WriteLine("Resulting set:       {0}", s.ToString(refList));
            Console.WriteLine("Adding the element   {0}", peuh2.ToString(refList));
            s.Add(peuh2);
            Console.WriteLine("Resulting set:       {0}", s.ToString(refList));
            Console.WriteLine("Removing the element {0}", peuh.ToString(refList));
            s.Remove(peuh);
            Console.WriteLine("Resulting set:       {0}", s.ToString(refList));
            Console.WriteLine("Removing the element {0}", peuh2.ToString(refList));
            s.Remove(peuh2);
            Console.WriteLine("Resulting set:       {0}", s.ToString(refList));
            Console.WriteLine("----------------------------------------------------------------------");
            Console.WriteLine("Empty set:           {0}", s.ToString(refList));
            Console.WriteLine("Adding the element   {0}", peuh.ToString(refList));
            s += peuh;
            Console.WriteLine("Resulting set:       {0}", s.ToString(refList));
            Console.WriteLine("Adding the element   {0}", peuh.ToString(refList));
            s += peuh;
            Console.WriteLine("Resulting set:       {0}", s.ToString(refList));
            Console.WriteLine("Adding the element   {0}", peuh2.ToString(refList));
            s += peuh2;
            Console.WriteLine("Resulting set:       {0}", s.ToString(refList));
            Console.WriteLine("Removing the element {0}", peuh.ToString(refList));
            s -= peuh;
            Console.WriteLine("Resulting set:       {0}", s.ToString(refList));
            Console.WriteLine("Removing the element {0}", peuh2.ToString(refList));
            s -= peuh2;
            Console.WriteLine("Resulting set:       {0}", s.ToString(refList));
            Console.WriteLine("----------------------------------------------------------------------");
            Console.WriteLine("Generating a set of 4 atoms.");
            s = DiscreteSet.GenerateSetOfAtoms(4);
            Console.WriteLine("Resulting set: {0}", s);
            Console.WriteLine("Number of elements: {0}", s.Card);
            Console.WriteLine("Size of elements: {0}", s.ElementSize);
            Console.WriteLine("----------------------------------------------------------------------");
            Console.WriteLine("Generating a set of 6 atoms.");
            s = DiscreteSet.GenerateSetOfAtoms(6);
            Console.WriteLine("Resulting set: {0}", s);
            Console.WriteLine("Number of elements: {0}", s.Card);
            Console.WriteLine("Size of elements: {0}", s.ElementSize);
            Console.WriteLine("----------------------------------------------------------------------");
            Console.WriteLine("Generating a set of 68 atoms.");
            s = DiscreteSet.GenerateSetOfAtoms(68);
            Console.WriteLine("Resulting set: {0}", s.ToStringOnePerLine());
            Console.WriteLine("Number of elements: {0}", s.Card);
            Console.WriteLine("Size of elements: {0}", s.ElementSize);
            Console.WriteLine("----------------------------------------------------------------------");
            Console.WriteLine("Generating a powerset with 4 worlds.");
            s = DiscreteSet.GeneratePowerSet(4);
            Console.WriteLine("Resulting set: {0}", s.ToStringOnePerLine());
            Console.WriteLine("Number of elements: {0}", s.Card);

            Console.WriteLine("Size of elements: {0}", s.ElementSize);
            Console.WriteLine("----------------------------------------------------------------------");
            Console.WriteLine("Generating a powerset with 6 worlds.");
            s = DiscreteSet.GeneratePowerSet(6);
            Console.WriteLine("Resulting set: {0}", s.ToStringOnePerLine());
            Console.WriteLine("Number of elements: {0}", s.Card);
            Console.WriteLine("Size of elements: {0}", s.ElementSize);
            Console.WriteLine("----------------------------------------------------------------------");
        }