Exemplo n.º 1
0
        public void Ommitsteps(Model m_mod)
        {
            GC.Collect();
            //ms.AddModel(m_mod.DeepCopy());
            Model        deepCopy  = m_mod.DeepCopy();
            List <Model> allModels = new List <Model>()
            {
                deepCopy
            };
            List <Model> lastModel = new List <Model>()
            {
                deepCopy
            };

            while (lastModel.Any())
            {
                List <Model> currentModels = new List <Model>();
                foreach (Model currentModel in lastModel)
                {
                    List <Model> allPossibleOneOmmits = OmmitOne(currentModel);
                    allModels.AddRange(allPossibleOneOmmits);
                    allModels.Add(currentModel);
                    currentModels.AddRange(allPossibleOneOmmits);
                }

                lastModel = currentModels;
            }

            //MessageBox.Show(allModels.Count+" models in ommit step");
            foreach (Model allModel in allModels)
            {
                //ms.AddModel(allModel);
                SaveHistoryModel(allModel, GenerateModelNameFromState(allModel));
            }
        }
Exemplo n.º 2
0
 private Model MergeRooms(Model mMod, MyRoom room, MyRoom modelRoom)
 {
     //Model m = mMod.DeepCopy();
     mMod = RemoveCommonWalls(mMod, room, modelRoom);
     //MergeBoundaryLineListToSmallerIdRooms();
     return(mMod);
 }
Exemplo n.º 3
0
        private void CostGrid_OnMouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            int   actualCostIndex = CostGrid.SelectedIndex;
            Model requested       = s.modelCopyHistory.ElementAt(actualCostIndex);

            model = requested;
            Paint();
        }
Exemplo n.º 4
0
        public void AllCasesTestGeneration()
        {
            Model m = new Model();

            m.InitTestModel();

            List <Model> newModelsBeforeStep = new List <Model>()
            {
                m
            };

            List <Model> allModels = new List <Model>()
            {
                m
            };
            int i = 0;

            while (newModelsBeforeStep.Any() && i < 10)
            {
                List <Model> newModelsInStep = new List <Model>();
                foreach (Model model in newModelsBeforeStep)
                {
                    List <Model> joinedModels = MergeAllRoomPairs(model);

                    foreach (Model currentModel in joinedModels)
                    {
                        if (currentModel.modelRooms.Count > 1)
                        {
                            newModelsInStep.Add(currentModel);
                        }
                    }

                    allModels.AddRange(joinedModels);
                }

                newModelsBeforeStep = newModelsInStep;
                i++;
            }

            MessageBox.Show(allModels.Count.ToString());
            ommitstepcount = 0;
            foreach (Model model in allModels)
            {
                Ommitsteps(model);
                ommitstepcount++;
                //if (ommitstepcount%10==0)
                //{
                //    MessageBox.Show(ommitstepcount.ToString());
                //}
            }
            string t = DateTime.Now.ToString("");

            //foreach (Model m1 in ms.getHistory()) {
            //    SaveHistoryModel(m1, GenerateModelNameFromState(m1));
            //}
            this.Close();
        }
Exemplo n.º 5
0
        private void LoadSelectedClick(object sender, RoutedEventArgs e)
        {
            int   actualCostIndex = CostGrid.SelectedIndex;
            Model requested       = s.modelCopyHistory.ElementAt(actualCostIndex);

            model   = requested;
            s.model = requested;
            Paint();
        }
Exemplo n.º 6
0
        private void ReStartSimulationClick(object sender, RoutedEventArgs e)
        {
            model = new Model();
            model.InitSimpleModel();
            s.model = model;
            Paint();

            Thread t = new Thread(s.run);

            t.Start();
        }
Exemplo n.º 7
0
        private void SimulationStepSwitch()
        {
            Dictionary <MyRoom, double> RoomCosts = new Dictionary <MyRoom, double>();

            double actualCost           = CostCalculationService.CalculateCost(model).First();
            double mincost              = actualCost;
            int    rooms                = model.modelRooms.Count;
            MyRoom switchThisMyRoomFrom = null;
            MyRoom switchThisMyRoomTo   = null;

            Parallel.For(0, rooms,
                         index => {
                Parallel.For(index + 1, rooms, secondindex => {
                    MyRoom r1       = model.modelRooms.ElementAt(index);
                    MyRoom r2       = model.modelRooms.ElementAt(secondindex);
                    MyRoom r1target = null;
                    MyRoom r2target = null;
                    Model tempModel = model.DeepCopy(r1, r2, out r1target, out r2target);
                    tempModel.SwitchRooms(ref r1target, ref r2target);

                    double cost = CostCalculationService.CalculateCost(tempModel).First();
                    lock (locker) {
                        RoomCosts.Add(r1, cost);
                        if (mincost >= cost)
                        {
                            mincost = cost;
                            //this might need to be switched later
                            switchThisMyRoomFrom = r1;
                            switchThisMyRoomTo   = r2;
                        }
                    }
                });
            });

            if (mincost >= actualCost)
            {
                actualSimulationThreshold++;
            }


            if (switchThisMyRoomFrom != null && switchThisMyRoomTo != null)
            {
                model.SwitchRooms(ref switchThisMyRoomFrom, ref switchThisMyRoomTo);
            }
            else
            {
                MessageBox.Show("no room to switch");
            }

            double[] costArray = CostCalculationService.CalculateCost(model);

            SimulationCosts.Add(new Costs(actualSimulationIndex, costArray[0], costArray[1], costArray[2], costArray[3]));
            actualSimulationIndex++;
        }
Exemplo n.º 8
0
        public List <Model> MergeAllRoomPairs(Model m_mod)
        {
            int missinglargest = 0;

            m_mod.CalculateAllRooms();
            IEnumerable <int> enumerable = fullist.Except(m_mod.modelRooms.Select(i => i.GetNumberAsInt()));

            if (enumerable.Any())
            {
                missinglargest = enumerable.Max();
            }
            //missinglargest = m_mod.modelRooms.Select(i => int.Parse(i.Number)).Union(fullist).Max();
            List <Model> returnList = new List <Model>();

            for (var i = 0; i < m_mod.modelRooms.Count; i++)
            {
                MyRoom room = m_mod.modelRooms[i];
                if (room.GetNumberAsInt() < missinglargest)
                {
                    continue;
                }

                for (var j = i + 1; j < m_mod.modelRooms.Count; j++)
                {
                    MyRoom modelRoom = m_mod.modelRooms[j];
                    if (modelRoom.GetNumberAsInt() < missinglargest)
                    {
                        continue;
                    }
                    //if (room2.Guid == room1.Guid) continue;

                    bool a = DoTheyHaveCommmonWall(room, modelRoom);
                    if (!a)
                    {
                        continue;
                    }

                    else
                    {
                        MyRoom room2;
                        MyRoom modelRoom2;
                        Model  m_mod2 = m_mod.DeepCopy(room, modelRoom, out room2, out modelRoom2);

                        Model newModel = MergeRooms(m_mod2, room2, modelRoom2);
                        returnList.Add(newModel);
                    }
                }
            }

            return(returnList);
        }
Exemplo n.º 9
0
        private void SaveHistoryModel(Model ms, string name)
        {
            //string data = JsonConvert.SerializeObject(jsondata);
            JsonSerializer serializer = new JsonSerializer();

            serializer.Formatting = Newtonsoft.Json.Formatting.Indented;
            serializer.Converters.Add(new JavaScriptDateTimeConverter());
            serializer.NullValueHandling     = NullValueHandling.Ignore;
            serializer.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;

            using (StreamWriter sw = new StreamWriter($"{savepath}\\Models\\{name}.json"))
                using (JsonWriter writer = new JsonTextWriter(sw)) {
                    serializer.Serialize(writer, ms);
                }
        }
Exemplo n.º 10
0
        private void LoadFirstModel()
        {
            string pat0h = @"C:\Users\Master\Desktop\Models\Modell_1-2_6_04-17-16-821.json";
            string path  = @"C:\Users\Master\Desktop\Models\Modell_1-2-3-4-5-6-7-8-9_24_07-05-17-014.json";
            string path4 = @"C:\Users\Master\Desktop\Models\Modell_1-2_6_07-05-20-733.json";
            string path5 = @"C:\Users\Master\Desktop\Models\Modell_1-2_7_07-05-17-584.json";
            string path6 = @"C:\Users\Master\Desktop\Models\Modell_1-2-3-4_13_07-05-17-471.json";

            using (StreamReader r = new StreamReader(path)) {
                string json  = r.ReadToEnd();
                Model  items = JsonConvert.DeserializeObject <Model>(json);
                model = items;
            }
            model.CalculateAllRooms();
            LoadDataFromModel();
            Paint();
        }
Exemplo n.º 11
0
        private Model RemoveCommonWalls(Model m, MyRoom room1, MyRoom room2)
        {
            List <MyLine> common = room1.BoundaryLines.Intersect(room2.BoundaryLines).ToList();

            foreach (MyLine line in common)
            {
                room1.BoundaryLines.Remove(line);
                room2.BoundaryLines.Remove(line);
                m.modelLines.Remove(line);
                foreach (MyRoom room in m.modelRooms)
                {
                    room.BoundaryLines.Remove(line);
                }
                line.EndMyPoint.RelatedLines.Remove(line);
                line.StartMyPoint.RelatedLines.Remove(line);
            }
            room1.BoundaryLines.AddRange(room2.BoundaryLines);
            room2.BoundaryLines.AddRange(room1.BoundaryLines);

            int  result1;
            int  result2;
            bool parsed1 = int.TryParse(room1.Number, out result1);
            bool parsed2 = int.TryParse(room2.Number, out result2);

            if (parsed1 && parsed2 && (result1 < result2 && room2.GetNumberAsInt() != 2))
            {
                m.modelRooms.Remove(room2);
                foreach (MyLine line in m.modelLines)
                {
                    line.relatedRooms.Remove(room2);
                }
            }
            else
            {
                m.modelRooms.Remove(room1);
                foreach (MyLine line in m.modelLines)
                {
                    line.relatedRooms.Remove(room1);
                }
            }

            return(m);
        }
Exemplo n.º 12
0
        public MainWindow()
        {
            //CreateRunFolderAndInitPath();
            model                 = new Model();
            Points                = new ObservableCollection <MyPoint>();
            Lines                 = new ObservableCollection <MyLine>();
            Rooms                 = new ObservableCollection <MyRoom>();
            SimulationCosts       = new ObservableCollection <Costs>();
            LineAndCostActualStep = new ObservableCollection <LineAndCost>();

            InitRoomTypes();
            model.InitSimpleModel();
            s.model         = model;
            s.ModelChanged += ModelChangeHandler;
            DataContext     = this;
            InitializeComponent();
            Paint();
            LoadDataFromModel();
        }
Exemplo n.º 13
0
        private List <Model> OmmitOne(Model currentModel)
        {
            if (currentModel.modelRooms.Count < 2)
            {
                return(new List <Model>());
            }
            List <Model> returns = new List <Model>()
            {
            };

            GC.Collect();
            foreach (var room in currentModel.modelRooms)
            {
                int missinglargest           = 0;
                IEnumerable <int> enumerable = fullist.Except(currentModel.modelRooms.Select(i => i.GetNumberAsInt()));

                if (enumerable.Any())
                {
                    missinglargest = enumerable.Max();
                }
                if (room.GetNumberAsInt() < missinglargest || room.GetNumberAsInt() == 2)
                {
                    continue;
                }

                MyRoom room2;
                Model  m_mod2 = currentModel.DeepCopy(room, out room2);

                foreach (MyLine line in room2.BoundaryLines)
                {
                    line.relatedRooms.Remove(room2);
                }
                m_mod2.modelRooms.Remove(room2);

                foreach (MyLine line in m_mod2.modelLines)
                {
                    line.relatedRooms.Remove(room2);
                }



                List <MyLine> toremove = new List <MyLine>();
                foreach (MyLine line in m_mod2.modelLines)
                {
                    if (!line.relatedRooms.Any())
                    {
                        toremove.Add(line);
                    }
                }

                foreach (MyLine line in toremove)
                {
                    m_mod2.modelLines.Remove(line);
                    foreach (var rooms in model.modelRooms)
                    {
                        rooms.BoundaryLines.Remove(line);
                    }
                    line.StartMyPoint.RelatedLines.Remove(line);
                    line.EndMyPoint.RelatedLines.Remove(line);
                }
                returns.Add(m_mod2);
            }

            return(returns);
        }
Exemplo n.º 14
0
 private string GenerateModelNameFromState(Model currentModel)
 {
     return
         ($"Modell_{string.Join("-",currentModel.modelRooms.Select(i=>i.Number))}_{currentModel.modelLines.Count}_{DateTime.Now.ToString("hh-mm-ss-fff")}");
 }
Exemplo n.º 15
0
        private void SimulationStepMove()
        {
            Dictionary <string, double> Costs = new Dictionary <string, double>();
            MyLine minline             = null;
            int    currentMoveDistance = moveDistance;
            double actualCost          = CostCalculationService.CalculateCost(model).First();
            double mincost             = actualCost;

            Parallel.For(0, model.modelLines.Count,
                         index => {
                MyLine myLine    = model.modelLines.ElementAt(index);
                MyLine newMyLine = null;
                Model tempModel  = model.DeepCopy(myLine, out newMyLine);
                tempModel.MoveLine(moveDistance, newMyLine);

                double cost = CostCalculationService.CalculateCost(tempModel).First();
                lock (locker) {
                    Costs.Add("+" + myLine.ToString(), cost);
                    if (mincost > cost)
                    {
                        mincost             = cost;
                        minline             = myLine;
                        currentMoveDistance = moveDistance;
                    }
                }
            });

            Parallel.For(0, model.modelLines.Count,
                         index => {
                MyLine myLine    = model.modelLines.ElementAt(index);
                MyLine newMyLine = null;
                Model tempModel  = model.DeepCopy(myLine, out newMyLine);
                tempModel.MoveLine(-moveDistance, newMyLine);

                double cost = CostCalculationService.CalculateCost(tempModel).First();
                lock (locker) {
                    Costs.Add("-" + myLine.ToString(), cost);
                    if (mincost > cost)
                    {
                        mincost             = cost;
                        minline             = myLine;
                        currentMoveDistance = -moveDistance;
                    }
                }
            });

            if (mincost >= actualCost)
            {
                actualSimulationThreshold++;
            }
            if (minline != null)
            {
                model.MoveLine(currentMoveDistance, minline);
            }
            else
            {
                MessageBox.Show("no line to move");
            }
            LineAndCostActualStep.Clear();
            foreach (var item in Costs)
            {
                LineAndCostActualStep.Add(new LineAndCost(item.Key, item.Value, actualSimulationIndex));
            }
            //System.Windows.Forms.MessageBox.Show(mincost.ToString());
            //SimulationCosts.Add(new Costs(actualSimulationIndex, mincost));

            double[] costArray = CostCalculationService.CalculateCost(model);
            SimulationCosts.Add(new Costs(actualSimulationIndex, costArray[0], costArray[1], costArray[2], costArray[3]));

            actualSimulationIndex++;
        }