예제 #1
0
 private int GetInterlayerIndex(InterlayerProperties interlayer)
 {
     return(AnalysisCast.GetInterlayerIndex(interlayer));
 }
예제 #2
0
        public void RebuildSolutionItemList()
        {
            try
            {
                ConstraintSetAbstract constraintSet = Analysis.ConstraintSet;
                double zTop   = Analysis.Offset.Z;
                double weight = Analysis.ContainerWeight;
                int    number = 0;

                List <SolutionItem> solutionItems = new List <SolutionItem>();
                foreach (SolutionItem solItem in _solutionItems)
                {
                    number += _layerTypes[index : solItem.IndexLayer].Count;
                    weight += _layerTypes[index : solItem.IndexLayer].Count * Analysis.ContentWeight;
                    zTop   += _layerTypes[solItem.IndexLayer].LayerHeight + ((-1 != solItem.InterlayerIndex) ? AnalysisCast.Interlayer(solItem.InterlayerIndex).Thickness : 0.0);

                    solutionItems.Add(solItem);

                    if (constraintSet.OneCriterionReached(zTop, weight, number, solutionItems.Count))
                    {
                        break;
                    }
                }

                // add layers until
                while (!constraintSet.OneCriterionReached(zTop, weight, number, solutionItems.Count))
                {
                    SolutionItem solItem = null;
                    if (solutionItems.Count > 0)
                    {
                        solItem = solutionItems.Last();
                    }
                    else
                    {
                        solItem = new SolutionItem(0, -1, false, false);
                    }

                    if (solItem.IndexLayer >= _layerTypes.Count)
                    {
                        throw new Exception(string.Format("Layer index out of range!"));
                    }

                    number += _layerTypes[solItem.IndexLayer].Count;
                    weight += _layerTypes[solItem.IndexLayer].Count * Analysis.ContentWeight;

                    // using zTopAdded because zTop must not be incremented if SolutionItem object is
                    // not actually added
                    double zTopIfAdded = zTop + _layerTypes[solItem.IndexLayer].LayerHeight
                                         + ((-1 != solItem.InterlayerIndex) ? AnalysisCast.Interlayer(solItem.InterlayerIndex).Thickness : 0.0);

                    // only checking on height because weight / number can be modified without removing
                    // a layer (while outputing solution as a list of case)
                    if (!constraintSet.CritHeightReached(zTopIfAdded))
                    {
                        solutionItems.Add(new SolutionItem(solItem));
                        zTop = zTopIfAdded;
                    }
                    else
                    {
                        break;
                    }
                }
                // remove unneeded layer
                while (constraintSet.CritHeightReached(zTop) && solutionItems.Count > 0)
                {
                    SolutionItem solItem = solutionItems.Last();

                    if (solItem.IndexLayer >= _layerTypes.Count)
                    {
                        throw new Exception(string.Format("Layer index out of range!"));
                    }
                    number -= _layerTypes[solItem.IndexLayer].Count;
                    weight -= _layerTypes[solItem.IndexLayer].Count * Analysis.ContentWeight;
                    zTop   -= _layerTypes[solItem.IndexLayer].LayerHeight
                              + ((-1 != solItem.InterlayerIndex) ? AnalysisCast.Interlayer(solItem.InterlayerIndex).Thickness : 0.0);

                    solutionItems.Remove(solItem);
                }
                _solutionItems.Clear();
                _solutionItems = solutionItems;

                // reset bounding box to force recompute
                _bbox.Reset();
            }
            catch (Exception ex)
            {
                _log.Error(ex.ToString());
            }
        }