public static void TestCase()
        {
            Console.WriteLine("\n\n" +
                              "+--------------------------------------------------------------------+\n" +
                              "|                  GeneratorBeliefFromBeliefs Tests                  |\n" +
                              "+--------------------------------------------------------------------+"
                              );

            try
            {
                char d = Path.DirectorySeparatorChar;

                GeneratorDiscreteBeliefFromBeliefs generator = new GeneratorDiscreteBeliefFromBeliefs("Sleeping");
                Console.WriteLine("Loading a model with the custom directory format:");
                generator.LoadModel("Resources" + d + "BeliefsFromBeliefs" + d + "Sleeping", ModelFormat.MODEL_CUSTOM_DIRECTORY);
                Console.WriteLine(generator);

                Console.WriteLine("\n----------------------------------------------------------------------");
                Console.WriteLine("----------------------------------------------------------------------");
                Console.WriteLine("----------------------------------------------------------------------\n");

                Console.WriteLine("Loading the same model from an XML file:");
                generator.LoadModel("Resources" + d + "BeliefsFromBeliefs" + d + "XML" + d + "BFB.xml", ModelFormat.MODEL_XML_FILE);
                Console.WriteLine(generator);

                Console.WriteLine("\n----------------------------------------------------------------------");

                Console.WriteLine("Saving the model:");
                Console.Write("Saving a custom directory (Resources" + d + "BeliefsFromBeliefs" + d + "SavingTest)... ");
                generator.SaveModel("Resources" + d + "BeliefsFromBeliefs" + d + "SavingTest", ModelFormat.MODEL_CUSTOM_DIRECTORY);
                Console.WriteLine("done!");

                Console.Write("Saving an XML file (Resources" + d + "BeliefsFromBeliefs" + d + "XML" + d + "SavingTest.xml)... ");
                generator.SaveModel("Resources" + d + "BeliefsFromBeliefs" + d + "XML" + d + "SavingTest.xml", ModelFormat.MODEL_XML_FILE);
                Console.WriteLine("done!");

                Console.WriteLine("\n----------------------------------------------------------------------");

                GeneratorDiscreteBeliefFromRandomness randomGenerator = new GeneratorDiscreteBeliefFromRandomness(3, 3);
                List <DiscreteMassFunction>           toPropagate     = randomGenerator.ConstructEvidence(new object[5]);
                List <NamedMassFunction <DiscreteMassFunction, DiscreteElement> > named = new List <NamedMassFunction <DiscreteMassFunction, DiscreteElement> >();
                for (int i = 0; i < 5; i++)
                {
                    named.Add(new NamedMassFunction <DiscreteMassFunction, DiscreteElement>("Posture", toPropagate[i]));
                }
                List <DiscreteMassFunction> propagated = generator.ConstructEvidence(named.ToArray());

                for (int i = 0; i < 5; i++)
                {
                    Console.WriteLine("To propagate: {0}", toPropagate[i].ToString(generator.Mappings[0].References));
                    Console.WriteLine("Propagated : {0}", propagated[i].ToString(generator.References));
                    Console.WriteLine("----------------------------------------------------------------------");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Exemplo n.º 2
0
        public static void TestCase()
        {
            Console.WriteLine("\n\n" +
                              "+--------------------------------------------------------------------+\n" +
                              "|                GeneratorBeliefFromRandomness Tests                 |\n" +
                              "+--------------------------------------------------------------------+"
                              );
            Console.Write("How many possible worlds would you like? ");
            string command = Console.ReadLine();

            try
            {
                int size     = Convert.ToInt32(command);
                int nbFocals = 0;
                int nbMass   = 0;
                if (size > 1)
                {
                    Console.Write("How many focal elements would you like? ");
                    command  = Console.ReadLine();
                    nbFocals = Convert.ToInt32(command);
                    if (nbFocals > 0)
                    {
                        Console.Write("How many mass functions would you like to generate? ");
                        command = Console.ReadLine();
                        nbMass  = Convert.ToInt32(command);
                        if (nbMass <= 0)
                        {
                            throw new Exception();
                        }
                    }
                    else
                    {
                        throw new Exception();
                    }
                }
                else
                {
                    throw new Exception();
                }
                GeneratorDiscreteBeliefFromRandomness generator = new GeneratorDiscreteBeliefFromRandomness(size, nbFocals);
                List <DiscreteMassFunction>           masses    = generator.ConstructEvidence(new object[nbMass]);
                foreach (DiscreteMassFunction mass in masses)
                {
                    Console.WriteLine("----------------------------------------------------------------------\n{0}", mass.ToString());
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine("You don't really want to test anything, do you?");
            }
        }