Ejemplo n.º 1
0
 /// <summary>
 /// Write the encodings.variable values of feasible solutions into a file
 /// </summary>
 /// <param name="path">File name</param>
 public void PrintFeasibleVAR(string path)
 {
     try
     {
         if (Size() > 0)
         {
             int numberOfVariables = SolutionsList.ElementAt(0).Variable.Count();
             using (StreamWriter outFile = new StreamWriter(path))
             {
                 foreach (Solution s in this.SolutionsList)
                 {
                     if (s.OverallConstraintViolation == 0.0)
                     {
                         for (int i = 0; i < numberOfVariables; i++)
                         {
                             outFile.WriteLine(s.Variable[i].ToString());
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Logger.Log.Error("SolutionSet.PrintFeasibleVAR", ex);
         Console.Write(ex.StackTrace);
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Writes the decision encodings.variable values of the <code>Solution</code> solutions objects into the set in a file.
 /// </summary>
 /// <param name="path">The output file name</param>
 public void PrintVariablesToFile(string path)
 {
     try
     {
         if (Size() > 0)
         {
             int numberOfVariables = SolutionsList.ElementAt(0).Variable.Count();
             using (StreamWriter outFile = new StreamWriter(path))
             {
                 foreach (Solution s in this.SolutionsList)
                 {
                     for (int i = 0; i < numberOfVariables; i++)
                     {
                         outFile.Write(s.Variable[i].ToString() + " ");
                     }
                     outFile.Write(Environment.NewLine);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Logger.Log.Error("SolutionSet.PrintVariablesToFile", ex);
         Console.WriteLine(ex.StackTrace);
     }
 }
        /// <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);
            }
        }
Ejemplo n.º 4
0
        public List <string> GetVariable()
        {
            string        var     = "";
            List <string> varList = new List <string>();

            try
            {
                if (Size() > 0)
                {
                    int numberOfVariables = SolutionsList.ElementAt(0).Variable.Count();

                    foreach (Solution s in this.SolutionsList)
                    {
                        for (int i = 0; i < numberOfVariables; i++)
                        {
                            var += s.Variable[i].ToString();
                        }
                        varList.Add(var);
                        var = "";
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log.Error("SolutionSet.PrintVariablesToFile", ex);
                Console.WriteLine(ex.StackTrace);
            }
            return(varList);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Returns the index of the worst Solution using a <code>Comparator</code>.
        /// If there are more than one occurrences, only the index of the first one is returned
        /// </summary>
        /// <param name="comparator"><code>Comparator</code> used to compare solutions.</param>
        /// <returns>The index of the worst Solution attending to the comparator or <code>-1<code> if the SolutionSet is empty</returns>
        public int IndexWorst(IComparer <Solution> comparator)
        {
            int result = 0;

            if ((SolutionsList == null) || SolutionsList.Count == 0)
            {
                result = 0;
            }
            else
            {
                Solution worstKnown = SolutionsList.ElementAt(0),
                         candidateSolution;
                int flag;
                for (int i = 1; i < SolutionsList.Count; i++)
                {
                    candidateSolution = SolutionsList.ElementAt(i);
                    flag = comparator.Compare(worstKnown, candidateSolution);
                    if (flag == -1)
                    {
                        result     = i;
                        worstKnown = candidateSolution;
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Sorts a SolutionSet using a <code>Comparator</code>.
 /// </summary>
 /// <param name="comparator"><code>Comparator</code> used to sort</param>
 public void Sort(IComparer <Solution> comparator)
 {
     if (comparator == null)
     {
         Logger.Log.Error("SolutionSet.Sort: Comparator is null");
         return;
     }
     SolutionsList.Sort(comparator);
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Deletes the <code>Solution</code> at position i in the set.
 /// </summary>
 /// <param name="i">The position of the solution to remove.</param>
 public void Remove(int i)
 {
     if (i > SolutionsList.Count - 1)
     {
         Logger.Log.Warn("SolutionSet.Remove: Index out of bound.");
     }
     else
     {
         SolutionsList.RemoveAt(i);
     }
 }
Ejemplo n.º 8
0
        /// <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);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Returns the best Solution using a <code>Comparator</code>.
        /// If there are more than one occurrences, only the first one is returned.
        /// </summary>
        /// <param name="comparator"><code>Comparator</code> used to compare solutions.<code>Comparator</code> used to compare solutions.</param>
        /// <returns>The best Solution attending to the comparator or <code>null<code> if the SolutionSet is empty</returns>
        public Solution Best(IComparer <Solution> comparator)
        {
            Solution result;
            int      indexBest = IndexBest(comparator);

            if (indexBest < 0)
            {
                result = null;
            }
            else
            {
                return(SolutionsList.ElementAt(indexBest));
            }

            return(result);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Returns the worst Solution using a <code>Comparator</code>.Returns the worst Solution using a <code>Comparator</code>.
        /// If there are more than one occurrences, only the first one is returned
        /// </summary>
        /// <param name="comparator"><code>Comparator</code> used to compare solutions.</param>
        /// <returns>The worst Solution attending to the comparator or <code>null<code>The worst Solution attending to the comparator or <code>null<code> if the SolutionSet is empty</returns>
        public Solution Worst(IComparer <Solution> comparator)
        {
            Solution result;
            int      index = IndexWorst(comparator);

            if (index < 0)
            {
                result = null;
            }
            else
            {
                result = SolutionsList.ElementAt(index);
            }

            return(result);
        }
Ejemplo n.º 11
0
        private void SolutionsList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            UpdateSelectedMultiple(e, _viewModel.SelectedSolutions);
            _viewModel.RaisePropertyChanged();

            SolutionsList.UpdateLayout();
            if (e.AddedItems.Count == 1)
            {
                Solution item         = e.AddedItems[0] as Solution;
                var      listViewItem =
                    SolutionsList.ItemContainerGenerator.ContainerFromItem(item) as ListViewItem;
                if (item != null)
                {
                    listViewItem.Focus();
                }
            }
        }
Ejemplo n.º 12
0
        public string VariablesToString()
        {
            StringBuilder result = new StringBuilder();

            if (Size() > 0)
            {
                int numberOfVariables = SolutionsList.ElementAt(0).Variable.Count();

                foreach (Solution s in this.SolutionsList)
                {
                    for (int i = 0; i < numberOfVariables; i++)
                    {
                        result.Append(s.Variable[i].ToString() + " ");
                    }
                    result.Append("\r\n");
                }
            }

            return(result.ToString());
        }
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        private void Page_Load(object sender, EventArgs e)
        {
            // Verify that the current user has access to access this page
            // Removed by Mario Endara <*****@*****.**> (2004/11/04)
//            if (PortalSecurity.IsInRoles("Admins") == false)
//                PortalSecurity.AccessDeniedEdit();

            // If this is the first visit to the page, populate the site data
            if (Page.IsPostBack == false)
            {
                // Bind the Portals to the SolutionsList
                SolutionsList.DataSource = GetPortals();
                SolutionsList.DataBind();

                //Preselect default Portal
                if (SolutionsList.Items.FindByValue("Default") != null)
                {
                    SolutionsList.Items.FindByValue("Default").Selected = true;
                }
            }

            if (chkUseTemplate.Checked == false)
            {
                // Don't use a template portal, so show the EditTable
                // Remove the cache that can be setted by the new Portal, to get a "clean" PortalBaseSetting
                CurrentCache.Remove(Key.PortalBaseSettings());
                EditTable.DataSource = new SortedList(PortalSettings.GetPortalBaseSettings(null));
                EditTable.DataBind();
                EditTable.Visible     = true;
                SolutionsList.Enabled = false;
            }
            else
            {
                EditTable.Visible     = false;
                SolutionsList.Enabled = true;
            }
        }
Ejemplo n.º 14
0
 public virtual bool Add(int index, Solution solution)
 {
     SolutionsList.Insert(index, 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.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);
            }
        }
        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");
            }
        }
        /// <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);
        }