/// <summary> /// Read the data files and set up the MATLAB component. /// Would like to do this in a static constructor, but we don't have access to a /// HttpRequest object at that time, so it's not clear how to map the paths. /// </summary> private void init() { HttpRequest request = this.Context.Request; string dataDir = request.MapPath("Data"); string schemaDir = request.MapPath("Schema"); _logger.Debug("Loading SpecificPower.xml"); string specificPowerDataFile = Path.Combine(dataDir, "SpecificPower.xml"); string specificPowerSchemaFile = Path.Combine(schemaDir, "SpecificPower.xsd"); specificPowerData = new SpecificPowerDataManager(specificPowerDataFile, specificPowerSchemaFile); inputPowerCalc = new InputPowerCalculator(specificPowerData.Data); _logger.Debug("Loading Coolers.xml"); string coolerDataFile = Path.Combine(dataDir, "Coolers.xml"); string coolerSchemaFile = Path.Combine(schemaDir, "Coolers.xsd"); coolers = new CoolerCollection(coolerDataFile, coolerSchemaFile); foreach (Cooler c in coolers) { c.InputPowerCalculator = inputPowerCalc; } _logger.DebugFormat("{0} coolers loaded", coolers.Count); _logger.Debug("Loading Materials.xml"); string materialsDataFile = Path.Combine(dataDir, "Materials.xml"); string materialsSchemaFile = Path.Combine(schemaDir, "Materials.xsd"); materials = new MaterialsCollection(materialsDataFile, materialsSchemaFile); _logger.DebugFormat("{0} materials loaded", materials.Count); _logger.Debug("Loading Problems.xml"); string problemsDataFile = Path.Combine(dataDir, "Problems.xml"); string problemsSchemaFile = Path.Combine(schemaDir, "Problems.xsd"); problems = new ProblemCollection(problemsDataFile, problemsSchemaFile); _logger.DebugFormat("{0} problems loaded", problems.Count); _logger.Debug("Loading MathGates.xml"); string mathGateDataFile = Path.Combine(dataDir, "MathGates.xml"); string mathGateSchemaFile = Path.Combine(schemaDir, "MathGates.xsd"); mathGates = new MathGateCollection(mathGateDataFile, mathGateSchemaFile); _logger.DebugFormat("{0} math gates loaded", mathGates.Count); _logger.Debug("Initializing Optimizer"); optimizer = new Optimizer(coolers, materials); _logger.Debug("Initializaing SolutionChecker"); solutionChecker = new SolutionChecker(problems); _logger.Debug("Initializaing SteadyStateSimulator"); sim = new SteadyStateSimulator(); _logger.Debug("Initializing API"); api = new API(); }
private void button_FindAnswer_Click(object sender, EventArgs e) { if (choseenFigsPath.Count == 0) { MessageBox.Show("Не выбраны детали"); return; } InitConfiguration(); CleanDir(pathTmp); CleanDir(pathRes); // Масштабирование Size scaledLstSize = new Size((int)(lstSize.Width * scale), (int)(lstSize.Height * scale)); InputHandling.ScaleAllFigs(choseenFigsPath, pathTmp, scale); // Загрузка фигур Console.WriteLine("Starting process. " + DateTime.Now.Minute + ":" + DateTime.Now.Second); List <Figure> data = Figure.LoadFigures(pathTmp, srcFigColor, angleStep, borderDistance, figAmount); data.Sort(Figure.CompareFiguresBySize); Figure.UpdIndexes(data); Figure.DeleteWrongAngles(scaledLstSize.Width, scaledLstSize.Height, data); SolutionChecker.LoadFigures(data, pathPrologCode, scaleCoefs); Console.WriteLine("Figure loading finished. " + DateTime.Now.Minute + ":" + DateTime.Now.Second); // Поиск решения Console.WriteLine("Starting result finding. " + DateTime.Now.Minute + ":" + DateTime.Now.Second); var preDefArr = SolutionChecker.FindAnAnswer(data, scaledLstSize.Width, scaledLstSize.Height, pathPrologCode, scaleCoefs); var result = SolutionChecker.PlacePreDefinedArrangement(preDefArr, scaledLstSize.Width, scaledLstSize.Height, scaleCoefs); if (result == null) { MessageBox.Show("Prolog finished. No answer."); } else { MessageBox.Show("Prolog finished. Answer was found."); // Отображение решения Console.WriteLine("Starting visualization. " + DateTime.Now.Minute + ":" + DateTime.Now.Second); OutputImage.SaveResult(data, preDefArr, result, pathRes, scaledLstSize.Width, scaledLstSize.Height); OutputText.SaveResult(preDefArr, data, result, pathRes + "result.txt"); } Console.WriteLine("Process finished. " + DateTime.Now.Minute + ":" + DateTime.Now.Second); Console.ReadLine(); }