private void GenerateChainButton_Click(object sender, RoutedEventArgs e) { ChainsList.Clear(); ResultChains.Clear(); ChainList.Items.Clear(); int groupsCount = GraphCanvas.Children.OfType<Group>().Count(); int i = 0; if (!Nodes.Any()) { Node parentNode = new Node(0); parentNode.Id = i; Nodes.Add(parentNode); foreach (var node in GraphCanvas.Children.OfType<Node>()) { i++; node.Id = i; Nodes.Add(node); if (node.GroupId == 1) { Nodes[0].Children.Add(node); } } } DFS(Nodes[0], new List<Node>()); #if DEBUG string str = ""; #endif foreach (var list in ChainsList) { if (list.Count == groupsCount) { ResultChains.Add(new List<Node>(list)); #if DEBUG foreach (var node in list) { str += node.Id; } ChainList.Items.Add(str); str = ""; #endif } } #if DEBUG ChainList.Visibility = Visibility.Visible; #endif ChainList.Items.Clear(); OptimisationService optimisationService = new OptimisationService(); Dictionary<string, int>[] dictionaries = new Dictionary<string, int>[GraphCanvas.GroupsCount]; foreach (var chain in ResultChains) { for (int j = 0; j < GraphCanvas.GroupsCount; j++) { dictionaries[j] = chain[j].OptimisationParams; } optimisationService.BruteForce(dictionaries); } List<KeyValuePair<string, int>> result = optimisationService.GetResult(); foreach (var res in result) { ChainList.Items.Add(res.Key); } }
private void GenerateChainButton_Click(object sender, RoutedEventArgs e) { ChainsList.Clear(); ResultChains.Clear(); ChainList.Items.Clear(); int groupsCount = GraphCanvas.Children.OfType <Group>().Count(); int i = 0; if (!Nodes.Any()) { Node parentNode = new Node(0); parentNode.Id = i; Nodes.Add(parentNode); foreach (var node in GraphCanvas.Children.OfType <Node>()) { i++; node.Id = i; Nodes.Add(node); if (node.GroupId == 1) { Nodes[0].Children.Add(node); } } } DFS(Nodes[0], new List <Node>()); #if DEBUG string str = ""; #endif foreach (var list in ChainsList) { if (list.Count == groupsCount) { ResultChains.Add(new List <Node>(list)); #if DEBUG foreach (var node in list) { str += node.Id; } ChainList.Items.Add(str); str = ""; #endif } } #if DEBUG ChainList.Visibility = Visibility.Visible; #endif ChainList.Items.Clear(); OptimisationService optimisationService = new OptimisationService(); Dictionary <string, int>[] dictionaries = new Dictionary <string, int> [GraphCanvas.GroupsCount]; foreach (var chain in ResultChains) { for (int j = 0; j < GraphCanvas.GroupsCount; j++) { dictionaries[j] = chain[j].OptimisationParams; } optimisationService.BruteForce(dictionaries); } List <KeyValuePair <string, int> > result = optimisationService.GetResult(); foreach (var res in result) { ChainList.Items.Add(res.Key); } }