Ejemplo n.º 1
0
        private void RefreshBionicModel(TId fitnessCriterionId)
        {
            ClearBionicModel();

            ModelsConverterSettings conversionSettings = new ModelsConverterSettings()
            {
                FitnessCriterionId      = fitnessCriterionId,
                NeighborhoodSizePercent = Program.ApplicationSettings.NeighborhoodSizePercent,
                UseRecordPoint          = Program.ApplicationSettings.UseRecordPoint
            };

            try
            {
                bionicModel = ModelsConverter.ModelToBionicModel(optModel, conversionSettings);
            }
            catch (Exception ex)
            {
                // TODO: Move application name to settings
                MessageBox.Show(ex.Message, "opt.Bionic", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (bionicModel == null)
            {
                // TODO: Handle this properly
                return;
            }

            ListParameters();
        }
Ejemplo n.º 2
0
        private void CalculateFitness(BionicModel model, Population targetPopulation, BionicSolverSettings settings)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            if (targetPopulation == null)
            {
                throw new ArgumentNullException("targetPopulation");
            }

            BionicModel tempModel = InitTempBionicModel(model, targetPopulation);

            Model  optModel         = ModelsConverter.BionicModelToModel(tempModel);
            string exchangeFilePath = CreateExchangeFile(optModel, settings);

            // This call will wait for external application to exit
            RunCalculationApplication(exchangeFilePath, settings);

            optModel = modelProvider.Load(exchangeFilePath);
            foreach (Experiment experiment in optModel.Experiments.Values)
            {
                targetPopulation[experiment.Id].FitnessValue = experiment.CriterionValues[model.FitnessCriterion.Id];

                foreach (TId constraintId in optModel.FunctionalConstraints.Keys)
                {
                    targetPopulation[experiment.Id].ConstraintValues[constraintId] = experiment.ConstraintValues[constraintId];
                }
            }
        }
Ejemplo n.º 3
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            if (dialogSaveModel.ShowDialog() == DialogResult.OK)
            {
                int filterIndex = dialogSaveModel.FilterIndex;
                try
                {
                    switch (filterIndex)
                    {
                    // OPT model
                    case 2:
                        Model optModel = ModelsConverter.ConvertToOptimization(ModelStorage.Instance.Model);
                        XmlModelProvider.Save(optModel, dialogSaveModel.FileName);
                        break;

                    // OPT.ID model
                    case 1:
                    default:
                        XmlIdentificationModelProvider.Save(ModelStorage.Instance.Model, dialogSaveModel.FileName);
                        break;
                    }
                }
                catch (Exception ex)
                {
                    MessageBoxHelper.ShowError(ex.Message);
                }

                dialogSaveModel.FileName = string.Empty;
            }
        }
Ejemplo n.º 4
0
        public static void Do()
        {
            var converter = new ModelsConverter();

            using (var context = new ClimateContext())
            {
                var cities = context.Cities.Include(x => x.Country).ToList().Select(converter.ToDto).ToArray();
                var path   = "../../../../shared/data.json";
                File.WriteAllText(path, JsonConvert.SerializeObject(cities));
            }
        }
Ejemplo n.º 5
0
        private DroneDelivery CreateDroneDelivery(Delivery deliveryRequest)
        {
            DroneDelivery delivery = new DroneDelivery();

            delivery.DeliveryId = deliveryRequest.DeliveryId;

            delivery.Dropoff = LocationRandomizer.GetRandomLocation();
            delivery.Pickup  = LocationRandomizer.GetRandomLocation();

            delivery.Expedited     = delivery.Expedited;
            delivery.PackageDetail = ModelsConverter.GetPackageDetail(deliveryRequest.PackageInfo);

            return(delivery);
        }
Ejemplo n.º 6
0
        private void SetFunction(object parameter)
        {
            var function = FunctionsViewModel.SelectedItem;

            var step = function.Step;

            IinterpolationAlgoritm interpolation = new SimpleInterpolation();

            if (UseGoldenSection)
            {
                interpolation = new GoldenSectionSearch(function.Function);
            }

            //interpolation = new SimpleInterpolation(false);
            var marchingCubes = new MarchingCubes.Algoritms.MarchingCubes.MarchingCubesAlgorithm(function.Function, interpolation);
            var defaultSize   = 10;
            var region        = function.Region ?? new Region3D(0, defaultSize, 0, defaultSize, 0, defaultSize);
            var results       = marchingCubes.Generate(region, step, function.CountorLine);

            viewPort.Children.Remove(gridModel);
            var converter = new ModelsConverter();

            if (ShowGrid)
            {
                var grid = converter.RenderGrid(results.Grid, DrawVertexIndexes, null);
                viewPort.Children.Add(grid);

                gridModel = grid;
            }

            var model = converter.RenderMesh(results.Triangles, UseMeshNormals, ShowNormals, ShowTwoSided);

            viewPort.Children.Remove(meshModel);
            viewPort.Children.Add(model);
            meshModel = model;

            this.ShowFunctionsPanel = false;
        }