/// <summary> /// Inserts a solution in the list /// The decision variables can be null if the solution is read from a file; in /// that case, the domination tests are omitted /// </summary> /// <param name="solution">The solution to be inserted.</param> /// <returns>true if the operation success, and false if the solution is dominated or if an identical individual exists.</returns> public override bool Add(Solution solution) { if (SolutionsList.Count == 0) { SolutionsList.Add(solution); return(true); } else { List <Solution> copyList = SolutionsList.ToList(); foreach (Solution s in copyList) { int flag = dominance.Compare(solution, s); if (flag == -1) { // A solution in the list is dominated by the new one SolutionsList.Remove(s); } else if (flag == 0) { // Non-dominated solutions } else if (flag == 1) { // The new solution is dominated return(false); } } //At this point, the solution is inserted into the list SolutionsList.Add(solution); return(true); } }
/// <summary> /// Inserts a new solution into the SolutionSet. /// </summary> /// <param name="solution">The <code>Solution</code> to store</param> /// <returns>True If the <code>Solution</code> has been inserted, false otherwise.</returns> public virtual bool Add(Solution solution) { if (SolutionsList.Count == Capacity) { Logger.Log.Error("The population is full"); Logger.Log.Error("Capacity is : " + Capacity); Logger.Log.Error("\t Size is: " + this.Size()); return(false); } SolutionsList.Add(solution); return(true); }
public override void LoadData(XmlNode configNode, ResourceManager resourceManager) { base.LoadData(configNode, resourceManager); if (resourceManager.DataSolutionsCommonFile.ExistsLocal()) { var document = new XmlDocument(); document.Load(resourceManager.DataSolutionsCommonFile.LocalPath); var itemInfoNodes = document.SelectNodes("//Products/Product")?.OfType <XmlNode>().ToArray() ?? new XmlNode[] { }; foreach (var itemInfoNode in itemInfoNodes) { SolutionsList.Add(SolutionsItemInfo.FromXml(itemInfoNode, resourceManager.ClipartTab7SubCFolder)); } } if (resourceManager.DataNeedsSolutionsPartDFile.ExistsLocal()) { var document = new XmlDocument(); document.Load(resourceManager.DataNeedsSolutionsPartDFile.LocalPath); var node = document.SelectSingleNode(@"/SHIFT07D"); if (node == null) { return; } foreach (XmlNode childNode in node.ChildNodes) { var item = ListDataItem.FromXml(childNode); switch (childNode.Name) { case "SHIFT07DHeader": if (!String.IsNullOrEmpty(item.Value)) { HeadersItems.Add(item); } break; case "SHIFT07DCombo1": if (item.IsPlaceholder) { Combo1Placeholder = item.Value; } break; case "SHIFT07DCombo2": if (item.IsPlaceholder) { Combo2Placeholder = item.Value; } break; case "SHIFT07DCombo3": if (item.IsPlaceholder) { Combo3Placeholder = item.Value; } break; case "SHIFT07DCombo4": if (item.IsPlaceholder) { Combo4Placeholder = item.Value; } break; } } Clipart1Configuration = ClipartConfiguration.FromXml(node, "SHIFT07DClipart1"); Clipart2Configuration = ClipartConfiguration.FromXml(node, "SHIFT07DClipart2"); Clipart3Configuration = ClipartConfiguration.FromXml(node, "SHIFT07DClipart3"); CommonEditorConfiguration = TextEditorConfiguration.FromXml(node); HeadersEditorConfiguration = TextEditorConfiguration.FromXml(node, "SHIFT07DHeader"); Combo1Configuration = TextEditorConfiguration.FromXml(node, "SHIFT07DCombo1"); Combo2Configuration = TextEditorConfiguration.FromXml(node, "SHIFT07DCombo2"); Combo3Configuration = TextEditorConfiguration.FromXml(node, "SHIFT07DCombo3"); Combo4Configuration = TextEditorConfiguration.FromXml(node, "SHIFT07DCombo4"); SubHeader1Configuration = TextEditorConfiguration.FromXml(node, "SHIFT07DLinkText1"); SubHeader2Configuration = TextEditorConfiguration.FromXml(node, "SHIFT07DLinkText2"); SubHeader3Configuration = TextEditorConfiguration.FromXml(node, "SHIFT07DLinkText3"); SubHeader4Configuration = TextEditorConfiguration.FromXml(node, "SHIFT07DLinkText4"); } }
public override void LoadData(XmlNode configNode, ResourceManager resourceManager) { base.LoadData(configNode, resourceManager); if (resourceManager.DataSolutionsCommonFile.ExistsLocal()) { var document = new XmlDocument(); document.Load(resourceManager.DataSolutionsCommonFile.LocalPath); var itemInfoNodes = document.SelectNodes("//Products/Product")?.OfType <XmlNode>().ToArray() ?? new XmlNode[] { }; foreach (var itemInfoNode in itemInfoNodes) { SolutionsList.Add(SolutionsItemInfo.FromXml(itemInfoNode, resourceManager.ClipartTab7SubCFolder)); } } if (resourceManager.DataNeedsSolutionsPartFFile.ExistsLocal()) { var document = new XmlDocument(); document.Load(resourceManager.DataNeedsSolutionsPartFFile.LocalPath); var node = document.SelectSingleNode(@"/SHIFT07F"); if (node == null) { return; } foreach (XmlNode childNode in node.ChildNodes) { var item = ListDataItem.FromXml(childNode); switch (childNode.Name) { case "SHIFT07FHeader": if (!String.IsNullOrEmpty(item.Value)) { HeadersItems.Add(item); } break; case "SHIFT07FCombo1": if (!String.IsNullOrEmpty(item.Value)) { Combo1Items.Add(item); } break; case "SHIFT07FTab1": Tab1DefaultItem = SolutionsList.FirstOrDefault(needsItem => String.Equals( needsItem.SubHeaderDefaultValue, childNode.Attributes? .OfType <XmlAttribute>() .FirstOrDefault(a => String.Equals(a.Name, "MultiBoxValue", StringComparison.OrdinalIgnoreCase))?.Value, StringComparison.OrdinalIgnoreCase)); Tab1DefaultName = childNode.Attributes? .OfType <XmlAttribute>() .FirstOrDefault(a => String.Equals(a.Name, "TabName", StringComparison.OrdinalIgnoreCase))?.Value; break; case "SHIFT07FTab2": Tab2DefaultItem = SolutionsList.FirstOrDefault(needsItem => String.Equals( needsItem.SubHeaderDefaultValue, childNode.Attributes? .OfType <XmlAttribute>() .FirstOrDefault(a => String.Equals(a.Name, "MultiBoxValue", StringComparison.OrdinalIgnoreCase))?.Value, StringComparison.OrdinalIgnoreCase)); Tab2DefaultName = childNode.Attributes? .OfType <XmlAttribute>() .FirstOrDefault(a => String.Equals(a.Name, "TabName", StringComparison.OrdinalIgnoreCase))?.Value; break; case "SHIFT07FTab3": Tab3DefaultItem = SolutionsList.FirstOrDefault(needsItem => String.Equals( needsItem.SubHeaderDefaultValue, childNode.Attributes? .OfType <XmlAttribute>() .FirstOrDefault(a => String.Equals(a.Name, "MultiBoxValue", StringComparison.OrdinalIgnoreCase))?.Value, StringComparison.OrdinalIgnoreCase)); Tab3DefaultName = childNode.Attributes? .OfType <XmlAttribute>() .FirstOrDefault(a => String.Equals(a.Name, "TabName", StringComparison.OrdinalIgnoreCase))?.Value; break; case "SHIFT07FTab4": Tab4DefaultItem = SolutionsList.FirstOrDefault(needsItem => String.Equals( needsItem.SubHeaderDefaultValue, childNode.Attributes? .OfType <XmlAttribute>() .FirstOrDefault(a => String.Equals(a.Name, "MultiBoxValue", StringComparison.OrdinalIgnoreCase))?.Value, StringComparison.OrdinalIgnoreCase)); Tab4DefaultName = childNode.Attributes? .OfType <XmlAttribute>() .FirstOrDefault(a => String.Equals(a.Name, "TabName", StringComparison.OrdinalIgnoreCase))?.Value; break; } } CommonEditorConfiguration = TextEditorConfiguration.FromXml(node); HeadersEditorConfiguration = TextEditorConfiguration.FromXml(node, "SHIFT07FHeader"); Combo1Configuration = TextEditorConfiguration.FromXml(node, "SHIFT07FCombo1"); SubHeader1Configuration = TextEditorConfiguration.FromXml(node, "Tab1MultiBox"); SubHeader2Configuration = TextEditorConfiguration.FromXml(node, "Tab2MultiBox"); SubHeader3Configuration = TextEditorConfiguration.FromXml(node, "Tab3MultiBox"); SubHeader4Configuration = TextEditorConfiguration.FromXml(node, "Tab4MultiBox"); FormListConfiguration = FormListConfiguration.FromXml(node); } }
/// <summary> /// Adds a <code>Solution</code> to the archive. If the <code>Solution</code> /// is dominated by any member of the archive then it is discarded. If the /// <code>Solution</code> dominates some members of the archive, these are /// removed. If the archive is full and the <code>Solution</code> has to be /// inserted, one <code>Solution</code> of the most populated hypercube of /// the adaptive grid is removed. /// </summary> /// <param name="solution">The <code>Solution</code></param> /// <returns>true if the <code>Solution</code> has been inserted, false otherwise.</returns> public override bool Add(Solution solution) { var iterator = SolutionsList.ToList(); foreach (var element in iterator) { int flag = dominance.Compare(solution, element); if (flag == -1) { // The Individual to insert dominates other // individuals in the archive SolutionsList.Remove(element); int location = Grid.Location(element); if (Grid.GetLocationDensity(location) > 1) { //The hypercube contains Grid.RemoveSolution(location); //more than one individual } else { Grid.UpdateGrid(this); } } else if (flag == 1) { // An Individual into the file dominates the // solution to insert return(false); // The solution will not be inserted } } // At this point, the solution may be inserted if (Size() == 0) { //The archive is empty SolutionsList.Add(solution); Grid.UpdateGrid(this); return(true); } if (Size() < maxSize) { //The archive is not full Grid.UpdateGrid(solution, this); // Update the grid if applicable int loc; loc = Grid.Location(solution); // Get the location of the solution Grid.AddSolution(loc); // Increment the density of the hypercube SolutionsList.Add(solution); // Add the solution to the list return(true); } // At this point, the solution has to be inserted and the archive is full Grid.UpdateGrid(solution, this); int loca = Grid.Location(solution); if (loca == Grid.MostPopulated) { // The solution is in the // most populated hypercube return(false); // Not inserted } else { // Remove an solution from most populated area iterator = SolutionsList.ToList(); bool removed = false; foreach (var element in iterator) { if (!removed) { int location2 = Grid.Location(element); if (location2 == Grid.MostPopulated) { SolutionsList.Remove(element); Grid.RemoveSolution(location2); } } } // A solution from most populated hypercube has been removed, // insert now the solution Grid.AddSolution(loca); SolutionsList.Add(solution); } return(true); }