Exemplo n.º 1
0
 public void RunDummyModelSimulation()
 {
     try
     {
         DotNet.Bridge.ModelFactory.InsertModelFactory(new ModelFactory());
         ApplicationRunnerSingleThreaded applicationRunner = new ApplicationRunnerSingleThreaded();
         applicationRunner.initialize(new java.io.File("."), @"..\..\testData\dummyModel\DummyModelSimulation.oda");
         applicationRunner.runSingleThreaded();
     }
     catch (Exception e)
     {
         // TEST NOT COMPLETE YET
     }
 }
Exemplo n.º 2
0
        public void RunApplication(IModelFactory dotNetModelFactory)
        {
            if (dotNetModelFactory != null)
            {
                // Tell OpenDA what model factory to use
                ModelFactory.InsertModelFactory(dotNetModelFactory);
            }
            // run the openda application
            ApplicationRunnerSingleThreaded applicationRunner;

            try
            {
                applicationRunner = new ApplicationRunnerSingleThreaded();
                applicationRunner.initialize(new java.io.File(odaDirectoryName), odaFileName);
                applicationRunner.runSingleThreaded();
            }
            catch (Exception e)
            {
                String message = "Error running OpenDA application.\nDetailed error message: " + e.Message;
                ModelFactory.AppendLogMessage(message);
                Console.WriteLine(message);
                return;
            }

            if (true)             // TODO: applicationRunner.getStatus()== ApplicationRunnerJ2N.Status.FINISHED // DONE)
            {
                // get a reference to the model instance selected by the algorithm as optimal

                IAlgorithm          algorithm = applicationRunner.getAlgorithm();
                IStochModelInstance calibratedStochModel;
                if (algorithm is Dud)
                {
                    Dud dud = ((Dud)algorithm);
                    calibratedStochModel = dud.getBestEstimate();
                }
                else if (algorithm is SparseDud)
                {
                    SparseDud sparseDud = ((SparseDud)algorithm);
                    calibratedStochModel = sparseDud.getBestEstimate();
                }
                else if (algorithm is Powell)
                {
                    Powell powell = ((Powell)algorithm);
                    calibratedStochModel = powell.getBestEstimate();
                }
                else if (algorithm is Simplex)
                {
                    Simplex simplex = ((Simplex)algorithm);
                    calibratedStochModel = simplex.getBestEstimate();
                }
                else if (algorithm is AbstractSequentialAlgorithm)
                {
                    AbstractSequentialAlgorithm asAlgorithm = ((AbstractSequentialAlgorithm)algorithm);
                    calibratedStochModel = asAlgorithm.getMainModel();
                    if (calibratedStochModel == null)
                    {
                        Console.WriteLine("No main model set by ensemble algorithm");
                        return;
                    }
                }
                else
                {
                    Console.WriteLine("Unknown Algoritm type: " + algorithm.GetType());
                    return;
                }

                // Get the model instance out of the stochModel->java2dotnet->modelInstance layers
                if (calibratedStochModel is BBStochModelInstance)
                {
                    org.openda.interfaces.IModelInstance modelInstance = ((BBStochModelInstance)calibratedStochModel).getModel();
                    if (modelInstance is ModelInstanceN2J)
                    {
                        ResultingModelInstance = ((ModelInstanceN2J)modelInstance).getDotNetModelInstance();
                    }
                    else
                    {
                        string message = "Unknown java 2 dotnet model instance type: " + modelInstance.GetType();
                        ModelFactory.AppendLogMessage(message);
                        Console.WriteLine(message);
                    }
                }
                else
                {
                    string message = "Unknown Stoch model instance type: " + calibratedStochModel.GetType();
                    ModelFactory.AppendLogMessage(message);
                    Console.WriteLine(message);
                }
            }
        }