// run an alg runner with a RandomAlgGenerator from the inputted subset private void RunRandomButton_Click(object sender, EventArgs e) { try { List <int> algs = GetListFromAlgSet(Set, RangeBox.Text); algs = algs.Distinct().ToList(); var screen = new DefaultRunnerScreen(new AlgRunner(Info.GetCube(Set), new RandomAlgGenerator(algs), new AlgsFromFileStored(Info.GetAlgFileName(Set))), RunnerScreenCallback); screen.Text = Set.ToString() + " algs"; screen.KeyPreview = true; screen.Show(); this.Hide(); RecentSubsetFile.AddSet(RangeBox.Text.Trim(), Set); UpdateRecentSubsetSelector(); } catch (ArgumentException ex) { MessageBox.Show(ex.Message, "invalid range", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public List <string> GetSubsets(AlgSet set) { var doc = new XmlDocument(); doc.Load(Name); var xpath = $"subsets/{set.ToString()}/subset"; var nodes = doc.SelectNodes(xpath); List <string> subsetStrings = new List <string>(); for (var k = 0; k < nodes.Count; k++) { var node = nodes[k]; subsetStrings.Add(node.Attributes["value"].Value); } return(subsetStrings); }
//public List<Subset> GetSubsetsForAlgSet(AlgSet set) //{ // XmlDocument doc = new XmlDocument(); // doc.Load(@"subsets.xml"); // string xPath = "subsets/" + set.ToString(); // var node = doc.SelectSingleNode(xPath); // var subsetNodes = node.SelectNodes("subset"); // var subsets = new List<Subset>(); // for(int k = 0; k < subsetNodes.Count; k++) // { // var subsetNode = subsetNodes[k]; // var subset = new Subset { Name = subsetNode.Attributes["name"].Value, SubsetList = subsetNode.InnerText }; // subsets.Add(subset); // } // return subsets; //} /// <summary> /// Gets all subset groups and subsets for the given alg set /// </summary> /// <param name="set"></param> /// <returns></returns> public List <SubsetGroup> GetSubsetGroupsForAlgSet(AlgSet set) { XmlDocument doc = new XmlDocument(); doc.Load(Name); string xPath = "subsets/" + set.ToString(); var node = doc.SelectSingleNode(xPath); var groupNodes = node.SelectNodes("group"); var groups = new List <SubsetGroup>(); for (int k = 0; k < groupNodes.Count; k++) { var groupNode = groupNodes[k]; var groupName = groupNode.Attributes["name"].Value; var subsets = new List <Subset>(); var subsetNodes = groupNodes[k].SelectNodes(".//subset"); for (int i = 0; i < subsetNodes.Count; i++) { var subsetNode = subsetNodes[i]; var subset = new Subset { Name = subsetNode.Attributes["name"].Value, SubsetList = subsetNode.InnerText }; // check if subset is in a subgroup var parent = subsetNode.SelectSingleNode(".."); if (parent.Name.Equals("subgroup")) { subset.Subgroup = parent.Attributes["name"].Value; } subsets.Add(subset); } var subgroupNames = new List <string>(); var subgroupNodes = groupNode.SelectNodes("subgroup"); for (var i = 0; i < subgroupNodes.Count; i++) { subgroupNames.Add(subgroupNodes[i].Attributes["name"].Value); } var group = new SubsetGroup { Name = groupName, Subsets = subsets, SubgroupNames = subgroupNames }; groups.Add(group); } return(groups); }
public void AddSet(string setText, AlgSet set) { var doc = new XmlDocument(); doc.Load(Name); var parentNode = doc.SelectSingleNode($"subsets/{set.ToString()}"); var node = parentNode.SelectSingleNode($"subset[@value = '{setText}']"); var place = int.MaxValue; if (node != null) { place = int.Parse(node.Attributes["order"].Value); parentNode.RemoveChild(node); } var newNode = doc.CreateNode(XmlNodeType.Element, "subset", null); var orderAttribute = doc.CreateAttribute("order"); orderAttribute.Value = "1"; var valueAttribute = doc.CreateAttribute("value"); valueAttribute.Value = setText; newNode.Attributes.Append(orderAttribute); newNode.Attributes.Append(valueAttribute); parentNode.InsertBefore(newNode, parentNode.FirstChild); var refNode = newNode.NextSibling; while (refNode != null) { int order = int.Parse(refNode.Attributes["order"].Value); if (order >= place) { break; } if (order >= NumSubsetsPerSet) { parentNode.RemoveChild(refNode); break; } refNode.Attributes["order"].Value = (order + 1).ToString(); refNode = refNode.NextSibling; } doc.Save(Name); }
/// <summary> /// Gets all subsets of an alg set /// </summary> /// <param name="set"></param> /// <returns></returns> public List <CustomSubset> GetSubsets(AlgSet set) { List <CustomSubset> sets = new List <CustomSubset>(); var doc = new XmlDocument(); doc.Load(Name); var xpath = $"subsets/{set.ToString()}/subset"; var nodes = doc.SelectNodes(xpath); for (var k = 0; k < nodes.Count; k++) { var node = nodes[k]; var name = node.Attributes["name"].Value.ToString(); var subsetText = node.SelectSingleNode("rangeStr").InnerText; var customSet = new CustomSubset(name, subsetText, set); sets.Add(customSet); } return(sets); }
/// <summary> /// Gets a mapping of subset names to number lists for an alg set /// </summary> /// <param name="set"></param> public Dictionary <string, List <int> > GetNameMap(AlgSet set) { XmlDocument doc = new XmlDocument(); doc.Load(Name); string xPath = "subsets/" + set.ToString(); var node = doc.SelectSingleNode(xPath); var subsetNodes = node.SelectNodes(".//subset"); Dictionary <string, List <int> > names = new Dictionary <string, List <int> >(); for (int k = 0; k < subsetNodes.Count; k++) { var subsetNode = subsetNodes[k]; var key = subsetNode.Attributes["name"].Value; var rangeRext = subsetNode.InnerText; List <int> posNums = SubsetTools.GetListFromRanges(rangeRext, Info.GetNumPositionsInSet(set)); names.Add(subsetNode.Attributes["name"].Value, posNums); } return(names); }