public static List <PolygonalFace> UnaffectedRefFacesDuringInstallation(SubAssembly newSubAsm)
        {
            var insertionDirection = newSubAsm.Install.InstallDirection;
            //var notAffectedFacesInCom = newSubAsm.Install.Reference.CVXHull.Faces.ToList();
            //var halfOfRefCvh = newSubAsm.Install.Reference.CVXHull.Faces.Where(f => f.Normal.dotProduct(insertionDirection) < 0).ToList();

            /*foreach (var eachFace in halfOfRefCvh)
             * {
             *  foreach (var eachMovingVerticies in newSubAsm.Install.Moving.CVXHull.Vertices)
             *  {
             *      var ray = new Ray(eachMovingVerticies, insertionDirection);
             *      var faceAffected = GeometryFunctions.RayIntersectsWithFace(ray, eachFace);
             *      if (faceAffected)
             *          notAffectedFacesInCom.Remove(eachFace);
             *  }
             * }*/
            //return notAffectedFacesInCom;
            var unaffected1 = newSubAsm.Install.Reference.CVXHull.Faces.Where(f => f.Normal.dotProduct(insertionDirection) > -0.1)
                              .ToList();

            /*foreach (var fastener in newSubAsm.Secure.Fasteners)
             * {
             *  if (fastener.InstallDirection == null) continue;
             *  unaffected1 = unaffected1.Where(f => f.Normal.dotProduct(fastener.InstallDirection) > 0).ToList();
             * }*/

            return(unaffected1);
        }
示例#2
0
        private static double DetermineDistanceToSeparateHull(SubAssembly newSubAsm, Double[] insertionDirection)
        {
            var refMaxValue =
                GeometryFunctions.FindMaxPlaneHeightInDirection(newSubAsm.Install.Reference.CVXHull.Vertices,
                                                                insertionDirection);
            var refMinValue =
                GeometryFunctions.FindMinPlaneHeightInDirection(newSubAsm.Install.Reference.CVXHull.Vertices,
                                                                insertionDirection);

            var movingMaxValue =
                GeometryFunctions.FindMaxPlaneHeightInDirection(newSubAsm.Install.Moving.CVXHull.Vertices,
                                                                insertionDirection);
            var movingMinValue =
                GeometryFunctions.FindMinPlaneHeightInDirection(newSubAsm.Install.Moving.CVXHull.Vertices,
                                                                insertionDirection);

            var distanceToFree = Math.Abs(refMaxValue - movingMinValue);

            if (distanceToFree < 0)
            {
                distanceToFree = 0;
                throw new Exception("How is distance to free less than zero?");
            }
            return(distanceToFree + (movingMaxValue - movingMinValue) + (refMaxValue - refMinValue));
        }
        //initialize memoization with 2-Component (i.e., arc) subassemblies so heuristic works
        protected static void InitializeMemo()
        {
            foreach (Connection arc in Graph.arcs.Where(a => a is Connection))
            {
                var         Asm  = new HashSet <Component>(new Component[] { (Component)arc.From, (Component)arc.To });
                var         Fr   = new List <Component>(new Component[] { (Component)arc.From });
                var         dirs = new HashSet <int>(arc.InfiniteDirections);
                SubAssembly sa;
                if (AssemblyEvaluator.EvaluateSub(Graph, Asm, Fr, dirs, out sa) > 0)
                {
                    HashSet <Component> A = new HashSet <Component>(Asm);
                    MemoData            D = new MemoData(sa.Install.Time, sa);
                    Memo.Add(A, D);
                }
            }

            foreach (var node in Graph.nodes)
            {
                var component = (Component)node;
                var N         = new HashSet <Component>(new[] { component });
                var sa        = new SubAssembly(N, EvaluationForBinaryTree.ConvexHullsForParts[component.name], component.Mass,
                                                component.Volume, new Vertex(component.CenterOfMass));
                MemoData D = new MemoData(0, sa);
                Memo.Add(N, D);
            }
        }
示例#4
0
        /*private static void BuildingTaskTimeDictionary(SubAssembly subAssembly, double p)
         * {
         *  if (subAssembly == null) return;
         *  TaskTime.Add(subAssembly.Name, subAssembly.Install.Time);
         *
         *  BuildingTaskTimeDictionary(subAssembly.Install.Moving as SubAssembly, p);
         *  BuildingTaskTimeDictionary(subAssembly.Install.Reference as SubAssembly, p);
         * }*/

        private static void BuildingFollowingTimeDictionary(SubAssembly subAssembly, double p)
        {
            if (subAssembly.Install == null)
            {
                return;
            }
            FollowingTime.Add(subAssembly.Name, p);
            var secureTime   = 0.0;
            var movingTime   = 0.0;
            var rotationTime = 0.0;

            if (subAssembly.Secure != null)
            {
                secureTime = 0.2;
            }
            //if (subAssembly.MoveRoate != null) movingTime = subAssembly.MoveRoate.Time;
            if (subAssembly.Rotate != null)
            {
                rotationTime = subAssembly.Rotate.Time;
            }
            p = p + subAssembly.Install.Time + secureTime + movingTime + rotationTime;

            BuildingFollowingTimeDictionary(subAssembly.Install.Moving as SubAssembly, p);
            BuildingFollowingTimeDictionary(subAssembly.Install.Reference as SubAssembly, p);
        }
        public static double CheckStabilityForReference(SubAssembly newSubAsm, FootprintFace f)
        {
            var refCOM = newSubAsm.Install.Reference.CenterOfMass;

            CenterOfMassProjectionOnFootprintFace(f, refCOM);

            f.MinDisNeaEdg = double.PositiveInfinity;
            var x02 = f.COMP.Position[0];
            var y02 = f.COMP.Position[1];
            var z02 = f.COMP.Position[2];

            f.Height = Math.Sqrt(Math.Pow(x02 - refCOM.Position[0], 2) +
                                 Math.Pow(y02 - refCOM.Position[1], 2) +
                                 Math.Pow(z02 - refCOM.Position[2], 2));
            foreach (var edge in f.OuterEdges)
            {
                var edgeVector = edge.From.Position.subtract(edge.To.Position).normalize();
                var distanceOfEdgeToComProj = GeometryFunctions.DistanceBetweenLineAndVertex(edgeVector,
                                                                                             edge.From.Position, f.COMP.Position);
                if (distanceOfEdgeToComProj < f.MinDisNeaEdg)
                {
                    f.MinDisNeaEdg    = distanceOfEdgeToComProj;
                    f.IsComInsideFace = IsTheProjectionInsideOfTheFace(f, edge);
                }
            }
            var spf = Math.Pow(((2 / Math.PI) * (Math.Atan(f.Height / f.MinDisNeaEdg))), 2);

            f.RefS = spf;
            return(f.RefS);
        }
示例#6
0
 private void UpdateInternalStabilityInfo(SubAssembly sub, List <double> totaldof, double maxsigleDOF,
                                          List <double> totalSBscore, double minsigleSB)
 {
     sub.InternalStabilityInfo.OverAllDOF            = totaldof.Sum();
     sub.InternalStabilityInfo.MaxSingleDOF          = maxsigleDOF;
     sub.InternalStabilityInfo.OverAllTippingScore   = totalSBscore.Sum();
     sub.InternalStabilityInfo.MinSingleTippingScore = minsigleSB;
 }
 internal TreeCandidate(TreeCandidate tc)
 {
     parent   = tc.parent;
     sa       = tc.sa;
     RefNodes = tc.RefNodes;
     MovNodes = tc.MovNodes;
     G        = tc.G;
     H        = tc.H;
 }
示例#8
0
        internal static void BuildingInstallationTaskDictionary(SubAssembly subAssembly)
        {
            //if (subAssembly == null) return;
            if (subAssembly.PartNames.Count == 1)
            {
                OptimalOrientation.SubAssemAndParts.Add(subAssembly.PartNames[0], subAssembly);
            }
            else
            {
                OptimalOrientation.SubAssemAndParts.Add(subAssembly.Name, subAssembly);
            }
            //if (subAssembly.Install == null) return;
            if (subAssembly.PartNames.Count == 1)
            {
                return;
            }
            OptimalOrientation.InstTasks.Add(subAssembly.Name, subAssembly);

            var secureTime   = 0.0;
            var movingTime   = 0.0;
            var rotationTime = 0.0;

            if (subAssembly.Secure != null)
            {
                secureTime = 0.2;
            }
            if (subAssembly.Rotate != null)
            {
                rotationTime = subAssembly.Rotate.Time;
            }
            var taskTime = subAssembly.Install.Time + secureTime + movingTime + rotationTime;

            if (double.IsInfinity(taskTime))
            {
                if (double.IsInfinity(subAssembly.Install.Time))
                {
                    subAssembly.Install.Time = 5.0;
                }
                if (double.IsInfinity(secureTime))
                {
                    subAssembly.Install.Time = 5.0;
                }
                if (double.IsInfinity(movingTime))
                {
                    subAssembly.Install.Time = 5.0;
                }
                if (double.IsInfinity(rotationTime))
                {
                    subAssembly.Install.Time = 5.0;
                }
                taskTime = subAssembly.Install.Time + secureTime + movingTime + rotationTime;
            }
            OptimalOrientation.TaskTime.Add(subAssembly.Name, taskTime);
            BuildingInstallationTaskDictionary(subAssembly.Install.Moving as SubAssembly);
            BuildingInstallationTaskDictionary(subAssembly.Install.Reference as SubAssembly);
        }
示例#9
0
 private Vertex CombinedCenterOfMass(SubAssembly newSubassembly)
 {
     return
         (new Vertex(new[] { (newSubassembly.Install.Moving.CenterOfMass.Position[0] +
                              newSubassembly.Install.Reference.CenterOfMass.Position[0]) / 2,
                             (newSubassembly.Install.Moving.CenterOfMass.Position[1] +
                              newSubassembly.Install.Reference.CenterOfMass.Position[1]) / 2,
                             (newSubassembly.Install.Moving.CenterOfMass.Position[2] +
                              newSubassembly.Install.Reference.CenterOfMass.Position[2]) / 2 }));
 }
        protected static double F(out SubAssembly tree, HashSet <Component> A)
        {
            Count[A.Count]++;
            TimeEstmCounter++;
            TimeEstm++;

            if (Memo.ContainsKey(A) /*||
                                     * Memo.Keys.Any(k => k.Count == A.Count && k.All(kk => A.Any(a => a.name == kk.name)))*/)
            {
                tree = Memo[A].sa;
                return(Memo[A].Value);
            }

            var candidates = GetCandidates(A);

            candidates.Sort();

            var         best = double.PositiveInfinity;
            SubAssembly bestsa = null, bestReference = null, bestMoving = null;

            foreach (var tc in candidates)
            {
                if (tc.H >= best)
                {
                    break;
                }
                SubAssembly reference, moving;
                var         refTime    = F(out reference, tc.RefNodes);
                var         movTime    = F(out moving, tc.MovNodes);
                var         maxT       = Math.Max(refTime, movTime);
                var         evaluation = tc.sa.Install.Time + maxT;
                if (evaluation < best)
                {
                    best          = evaluation;
                    bestsa        = tc.sa;
                    bestReference = reference;
                    bestMoving    = moving;
                }
                if (Estimate)
                {
                    break;
                }
            }

            tree = bestsa;
            tree.Install.Reference = bestReference;
            tree.Install.Moving    = bestMoving;

            if (!Estimate)
            {
                var d = new MemoData(best, bestsa);
                Memo.Add(A, d);
            }
            return(best);
        }
        private static double StabilityEvaluation(SubAssembly newSubAsm, List <FootprintFace> FootPrintFaces)
        {
            double r = 0.0;

            foreach (var newFa in FootPrintFaces)
            {
                r += CheckStabilityForReference(newSubAsm, newFa);
            }
            r = r / FootPrintFaces.Count;
            return(r);
        }
        private static double InitialEvaluation(SubAssembly newSubAsm, double[] installDirection, List <Component> refNodes, List <Component> movingNodes, AssemblyCandidate c, double InstallTime)
        {
            newRefCVHFacesInCom.Clear();

            var unAffectedFaces = UnaffectedRefFacesDuringInstallation(newSubAsm);
            var mergedFaces     = MergingFaces(unAffectedFaces);

            c.TimeScore          = InstallTime;
            c.AccessibilityScore = AccessabilityEvaluation(installDirection, mergedFaces);
            c.StabilityScore     = StabilityEvaluation(newSubAsm, mergedFaces);
            return(c.TimeScore + c.AccessibilityScore + c.StabilityScore);
        }
        /// <summary>
        /// methods
        /// </summary>
        ///


        internal void Perform(Vertex insertionPoint, double[] insertionDirection, SubAssembly newSubAsm)
        {
            // Step #1: Creat ConvexHull Vertices for the SubAssembly
            //CreateConvexHullVertices(componentsInReference);
            var insertDir = new[] { insertionDirection[0], insertionDirection[1], insertionDirection[2] };

            // Step #2: Compute Accessiblity Metric
            ComputeAccessibleMetric(insertionPoint, insertDir);

            // Step #3: Compute Stability Metric
            ComputeStabilityMetric(insertionPoint, insertDir);
        }
        internal static void PrintAssemblyNodes(SubAssembly Tree)
        {
            var R = Tree.Install.Reference.PartNames;
            var M = Tree.Install.Moving.PartNames;
            var A = R.Concat(M);

            Console.Write("[" + Node2Int[A.First()]);
            foreach (var component in A.Skip(1))
            {
                Console.Write("," + Node2Int[component]);
            }
            Console.Write("] (" + A.Count() + ")");
        }
示例#15
0
        internal static void BuildingListOfReferencePreceedings(SubAssembly subAssembly)
        {
            //if (subAssembly.Install == null) return;
            if (subAssembly.PartNames.Count == 1)
            {
                return;
            }
            OptimalOrientation.RefPrec.Add(subAssembly);
            //if (subAssembly.Install.Moving.PartNames.Count > 1)
            var moving = subAssembly.Install.Moving as SubAssembly;

            OptimalOrientation.TempSucSubassem.Add(subAssembly.Install.Moving.PartNames.Count == 1
                ? subAssembly.Install.Moving.PartNames[0] : moving.Name);
            if (moving.Install != null)
            {
                OptimalOrientation.Movings.Add(subAssembly.Install.Moving as SubAssembly);
            }
            BuildingListOfReferencePreceedings(subAssembly.Install.Reference as SubAssembly);
        }
示例#16
0
        internal static void BuildSuccedingTaskDictionary(SubAssembly subAssembly, List <string> successors)
        {
            //if (subAssembly == null) return;
            if (subAssembly.PartNames.Count == 1)
            {
                return;
            }
            OptimalOrientation.SucTasks.Add(subAssembly.Name, successors);

            var subSubAssembly = subAssembly.Install.Moving;
            var subSuccessors  = new List <string>(successors);

            subSuccessors.Add(subAssembly.Name);
            BuildSuccedingTaskDictionary(subSubAssembly as SubAssembly, subSuccessors);
            subSubAssembly = subAssembly.Install.Reference;
            subSuccessors  = new List <string>(successors);
            subSuccessors.Add(subAssembly.Name);
            BuildSuccedingTaskDictionary(subSubAssembly as SubAssembly, subSuccessors);
        }
        internal static void PrintTree(SubAssembly Tree, int Level = 0)
        {
            if (Tree.Install == null)
            {
                return;
            }

            Console.Write(String.Concat(Enumerable.Repeat("    ", Level)));
            PrintAssemblyNodes(Tree);
            Console.WriteLine("");

            if (Tree.Install.Reference.PartNames.Count > 1)
            {
                PrintTree((SubAssembly)Tree.Install.Reference, Level + 1);
            }
            if (Tree.Install.Moving.PartNames.Count > 1)
            {
                PrintTree((SubAssembly)Tree.Install.Moving, Level + 1);
            }
        }
示例#18
0
        private HashSet <Double[]> InsertionDirectionsFromRemovalDirections(SubAssembly sub, List <Component> optNodes,
                                                                            HashSet <int> validDirs)
        {
            // Note: The hashset of validDirs are the removal directions to remove optNodes from the rest.
            //       If the optNodes is the reference, then the installDirections are the same as validDirs
            //       If the optNodes is the moving, then the InstallDirection is the opposite of the validDirs

            var dirs = new HashSet <Double[]>();

            if (sub.Install.Reference.PartNames.All(optNodes.Select(n => n.name).ToList().Contains) &&
                optNodes.Select(n => n.name).ToList().All(sub.Install.Reference.PartNames.Contains))
            {
                foreach (var dir in validDirs)
                {
                    dirs.Add(DisassemblyDirections.Directions[dir]);
                }
                return(dirs);
            }
            foreach (var dir in validDirs)
            {
                dirs.Add(DisassemblyDirections.Directions[dir].multiply(-1.0));
            }
            return(dirs);
        }
 public MemoData(double V, SubAssembly S)
 {
     Value = V;
     sa    = S;
 }
示例#20
0
        public SubAssembly Update(option opt, List <Component> rest, Dictionary <string, TVGLConvexHull> convexHullForParts)
        {
            Part refAssembly, movingAssembly;
            //if (ActionIsAssemblyByAssembly())
            //{
            //    //var node0 = (Component)opt.nodes[0];
            //    //var node1 = (Component)opt.nodes[1];
            //    //var node0name = node0.name;
            //    //var node1name = node1.name;
            //    //refAssembly = Subassemblies.FirstOrDefault(subasm => subasm.PartNames.Contains(node0name));
            //    //if (refAssembly == null)
            //    //    refAssembly = new Part(node0name, GetPartMass(node0), GetPartVolume(node0),
            //    //        convexHullForParts[node0name], GetPartCenterOfMass(node0));
            //    //else Subassemblies.Remove((SubAssembly) refAssembly);
            //    //movingAssembly = Subassemblies.FirstOrDefault(subasm => subasm.PartNames.Contains(node1name));
            //    //if (movingAssembly == null)
            //    //    movingAssembly = new Part(node1name, GetPartMass(node1), GetPartVolume(node1),
            //    //        convexHullForParts[node1name], GetPartCenterOfMass(node0));
            //    //else Subassemblies.Remove((SubAssembly) movingAssembly);
            //}
            //else if (ActionIsRemoveSCC())
            //{
            var movingNodes    = opt.Nodes.Cast <Component>().ToList();
            var newSubAsmNodes = rest;

            if (movingNodes.Count == 1)
            {
                var nodeName = movingNodes[0].name;
                movingAssembly = new Part(nodeName,
                                          GetPartMass(movingNodes[0]), GetPartVolume(movingNodes[0]),
                                          convexHullForParts[nodeName], GetPartCenterOfMass(movingNodes[0]));
            }
            else
            {
                var combinedCVXHullM = CreateCombinedConvexHull2(movingNodes, convexHullForParts);
                var VolumeM          = GetSubassemblyVolume(movingNodes);
                var MassM            = GetSubassemblyMass(movingNodes);
                var centerOfMass     = GetSubassemblyCenterOfMass(movingNodes);
                movingAssembly = new SubAssembly(new HashSet <Component>(movingNodes), combinedCVXHullM, MassM, VolumeM, centerOfMass);
            }

            var referenceHyperArcnodes = new List <Component>();

            referenceHyperArcnodes = newSubAsmNodes.Where(a => !movingNodes.Contains(a)).ToList();
            if (referenceHyperArcnodes.Count == 1)
            {
                var nodeName = referenceHyperArcnodes[0].name;
                refAssembly = new Part(nodeName,
                                       GetPartMass(referenceHyperArcnodes[0]), GetPartVolume(referenceHyperArcnodes[0]),
                                       convexHullForParts[nodeName], GetPartCenterOfMass(referenceHyperArcnodes[0]));
            }
            else
            {
                var combinedCVXHullR = CreateCombinedConvexHull2(referenceHyperArcnodes, convexHullForParts);
                var VolumeR          = GetSubassemblyVolume(referenceHyperArcnodes);
                var MassR            = GetSubassemblyMass(referenceHyperArcnodes);
                var centerOfMass     = GetSubassemblyCenterOfMass(referenceHyperArcnodes);
                refAssembly = new SubAssembly(new HashSet <Component>(referenceHyperArcnodes), combinedCVXHullR, MassR, VolumeR, centerOfMass);
            }
            //}
            //else throw new Exception("Only install rules in assembly at this point.");
            TVGLConvexHull combinedCVXHull = CreateCombinedConvexHull(
                refAssembly.CVXHull, movingAssembly.CVXHull);
            //List<PolygonalFace> refFacesInCombined, movingFacesInCombined;
            var InstallCharacter = shouldReferenceAndMovingBeSwitched(refAssembly, movingAssembly, combinedCVXHull,
                                                                      out refFacesInCombined, out movingFacesInCombined);

            if ((int)InstallCharacter < 0)
            {
                var tempASM = refAssembly;
                refAssembly        = movingAssembly;
                movingAssembly     = tempASM;
                refFacesInCombined = movingFacesInCombined; // no need to use temp here, as the movingFaces in the
                // combined convex hull are not needed.
                InstallCharacter = (InstallCharacterType)(-((int)InstallCharacter));
            }
            string refName        = NameMaker(refAssembly);
            string movName        = NameMaker(movingAssembly);
            var    newSubassembly = new SubAssembly(refAssembly, movingAssembly, combinedCVXHull, InstallCharacter,
                                                    refFacesInCombined);

            //newSubassembly.Name = refName +"   on   "+movName;
            newSubassembly.CenterOfMass = CombinedCenterOfMass(newSubassembly);
            // instead of adding to Subassemblies, newSubassembly must be added to its preceeding subassembly (to its parent)
            Subassemblies.Add(newSubassembly);
            return(newSubassembly);
        }
示例#21
0
        public const double TRANSFERSPEED = 0.8; // Transfer Speed: 0.1 (m/sec)

        public List <double> EvaluateTimeAndSDForInstall(List <Connection> connectingArcs, double travelDistance, double insertionDistance, SubAssembly newSubAsm)
        {
            // 1. Install          units are in kg and m
            // a. travel time

            var TimeAndSD  = new List <double>();
            var movingMass = newSubAsm.Install.Moving.Mass / 1000;
            var movingVol  = newSubAsm.Install.Moving.Volume / 1000000;

            //var movingVol = 1;
            var movingSpeed = new double();

            //var movingSpeed = 15.0;
            if (movingMass <= 1)
            {
                movingSpeed = 1;
            }
            else if (movingSpeed > 1 && movingSpeed <= 15)
            {
                movingSpeed = movingMass * (-8.0 / 140000.0) + 148.0 / 140.0;
            }
            else
            {
                movingSpeed = 0.2;
            }
            var traveltime    = travelDistance / movingSpeed;
            var DisTraveltime = 0.05;

            // b. contact info
            var insertiontime  = new double();
            var aligmentime    = new double();
            var DisAligmentime = new double();

            if (movingVol <= 0.000001)
            {
                aligmentime    = -4008 * movingVol + 5;
                DisAligmentime = 1;
            }
            else if (movingVol <= 0.001)
            {
                aligmentime    = 3;
                DisAligmentime = 1;
            }
            else
            {
                aligmentime    = 54.1 * movingVol + 2.95;
                DisAligmentime = movingVol * 50 + movingMass / 100;
            }

            if (insertionDistance != 0)
            {
                insertiontime = (insertionDistance / 1000) / Constants.MaxInsertionSpeed;
            }

            double installationTime = traveltime + aligmentime + insertiontime;
            double Disinstalltime   = DisTraveltime + DisAligmentime;

            // c. still need statbility


            //2. Secure:
            var bolttime    = new double();
            var DisBolttime = new double();

            foreach (var a in connectingArcs.Where(a => a.localVariables.Contains(DisConstants.BoltDepth)))
            {
                var boltLength = a.localVariables[a.localVariables.IndexOf(DisConstants.BoltDepth) + 1];
                bolttime    = bolttime + boltLength / Constants.boltinsertSpeed;
                DisBolttime = DisBolttime + bolttime - boltLength / (Constants.boltinsertSpeed + 0.2);
            }

            installationTime = installationTime + bolttime;
            Disinstalltime   = Disinstalltime + DisBolttime;
            TimeAndSD.Add(installationTime);
            TimeAndSD.Add(Disinstalltime);
            return(TimeAndSD);
        }
        protected static void InitializeMemoBoosted()
        {
            var newMemo = new List <HashSet <HashSet <Component> > >();

            for (var i = 1; i <= Graph.nodes.Count; i++)
            {
                var combinations = CombinationFinder(i);
                var column       = new HashSet <HashSet <Component> >();
                if (!combinations.Any())
                {
                    foreach (var node in Graph.nodes)
                    {
                        var component = (Component)node;
                        var N         = new HashSet <Component>(new[] { component });
                        var sa        = new SubAssembly(N, EvaluationForBinaryTree.ConvexHullsForParts[component.name],
                                                        component.Mass,
                                                        component.Volume, new Vertex(component.CenterOfMass));
                        var D = new MemoData(0, sa);
                        column.Add(N);
                        Memo.Add(N, D);
                    }
                    newMemo.Add(column);
                }
                else
                {
                    Parallel.ForEach(combinations, comb =>
                    {
                        foreach (var subAssem1 in newMemo[comb[0] - 1])
                        {
                            foreach (var subAssem2 in newMemo[comb[1] - 1])
                            {
                                if (subAssem1.Any(subAssem2.Contains))
                                {
                                    continue;
                                }
                                var connections =
                                    new HashSet <Connection>(
                                        subAssem1.SelectMany(
                                            n => n.arcs.Where(c => c is Connection).Cast <Connection>().Where(c =>
                                                                                                              (subAssem1.Contains(c.From) && subAssem2.Contains(c.To)) ||
                                                                                                              (subAssem1.Contains(c.To) && subAssem2.Contains(c.From)))));
                                var secConnections =
                                    new HashSet <SecondaryConnection>(
                                        subAssem1.SelectMany(
                                            n =>
                                            n.arcs.Where(a => a is SecondaryConnection)
                                            .Cast <SecondaryConnection>()
                                            .Where(c =>
                                                   (subAssem1.Contains(c.From) && subAssem2.Contains(c.To)) ||
                                                   (subAssem1.Contains(c.To) && subAssem2.Contains(c.From)))));

                                if (!connections.Any())
                                {
                                    continue;
                                }
                                var dirs = ValidDirectionsFinder(subAssem1, subAssem2, connections);
                                ApplySecondaryConnections(dirs, subAssem1, subAssem2, secConnections);
                                if (!dirs.Any())
                                {
                                    continue;
                                }
                                var asm = new HashSet <Component>(subAssem1);
                                asm.UnionWith(subAssem2);
                                SubAssembly sa;
                                if (AssemblyEvaluator.EvaluateSub(Graph, asm, subAssem1.ToList(), dirs, out sa) > 0)
                                {
                                    if (!Memo.ContainsKey(asm))
                                    {
                                        var D = new MemoData(sa.Install.Time, sa);
                                        lock (Memo)
                                            Memo.Add(asm, D);
                                        lock (column)
                                            column.Add(asm);
                                        continue;
                                    }
                                    if (sa.Install.Time < Memo[asm].Value)
                                    {
                                        lock (Memo)
                                            Memo[asm] = new MemoData(sa.Install.Time, sa);
                                    }
                                }
                            }
                        }
                    });
                    newMemo.Add(column);
                    if (newMemo.Count == 3)
                    {
                        break;
                    }
                }
            }
        }
示例#23
0
        /// <summary>
        /// returns the subassembly class given the two lists of components
        /// </summary>
        /// <param name="opt">The opt.</param>
        /// <param name="rest">The rest.</param>
        /// <returns>SubAssembly.</returns>
        public SubAssembly Update(List <Component> opt, List <Component> rest)
        {
            //todo: change List to HashSet
            Part refAssembly, movingAssembly;
            var  movingNodes    = opt;
            var  newSubAsmNodes = rest;

            if (movingNodes.Count == 1)
            {
                var nodeName = movingNodes[0].name;
                movingAssembly = new SubAssembly(new HashSet <Component>(movingNodes), ConvexHullsForParts[nodeName],
                                                 movingNodes[0].Mass,
                                                 movingNodes[0].Volume, new Vertex(movingNodes[0].CenterOfMass));
                //movingAssembly = new Part(nodeName, movingNodes[0].Volume, movingNodes[0].Volume,
                //    ConvexHullsForParts[nodeName], new Vertex(movingNodes[0].CenterOfMass));
            }
            else
            {
                var combinedCVXHullM = CreateCombinedConvexHull2(movingNodes);
                var VolumeM          = GetSubassemblyVolume(movingNodes);
                var MassM            = GetSubassemblyMass(movingNodes);
                var centerOfMass     = GetSubassemblyCenterOfMass(movingNodes);
                movingAssembly = new SubAssembly(new HashSet <Component>(movingNodes), combinedCVXHullM, MassM, VolumeM,
                                                 centerOfMass);
            }

            var referenceHyperArcnodes = new List <Component>();

            referenceHyperArcnodes = (List <Component>)newSubAsmNodes.Where(a => !movingNodes.Contains(a)).ToList();
            if (referenceHyperArcnodes.Count == 1)
            {
                var nodeName = referenceHyperArcnodes[0].name;
                refAssembly = new SubAssembly(new HashSet <Component>(referenceHyperArcnodes),
                                              ConvexHullsForParts[nodeName],
                                              referenceHyperArcnodes[0].Mass, referenceHyperArcnodes[0].Volume,
                                              new Vertex(referenceHyperArcnodes[0].CenterOfMass));
                //refAssembly = new Part(nodeName, referenceHyperArcnodes[0].Mass, referenceHyperArcnodes[0].Volume,
                //    ConvexHullsForParts[nodeName],
                //   new Vertex(referenceHyperArcnodes[0].CenterOfMass));
            }
            else
            {
                var combinedCVXHullR = CreateCombinedConvexHull2(referenceHyperArcnodes);
                var VolumeR          = GetSubassemblyVolume(referenceHyperArcnodes);
                var MassR            = GetSubassemblyMass(referenceHyperArcnodes);
                var centerOfMass     = GetSubassemblyCenterOfMass(referenceHyperArcnodes);
                refAssembly = new SubAssembly(new HashSet <Component>(referenceHyperArcnodes), combinedCVXHullR, MassR,
                                              VolumeR, centerOfMass);
            }
            var combinedCvxHull = CreateCombinedConvexHull(refAssembly.CVXHull, movingAssembly.CVXHull);
            List <PolygonalFace> movingFacesInCombined;
            List <PolygonalFace> refFacesInCombined;
            var InstallCharacter = shouldReferenceAndMovingBeSwitched(refAssembly, movingAssembly, combinedCvxHull,
                                                                      out refFacesInCombined, out movingFacesInCombined);

            if ((int)InstallCharacter < 0)
            {
                var tempASM = refAssembly;
                refAssembly        = movingAssembly;
                movingAssembly     = tempASM;
                refFacesInCombined = movingFacesInCombined; // no need to use temp here, as the movingFaces in the
                // combined convex hull are not needed.
                InstallCharacter = (InstallCharacterType)(-((int)InstallCharacter));
            }
            var newSubassembly = new SubAssembly(refAssembly, movingAssembly, combinedCvxHull, InstallCharacter,
                                                 refFacesInCombined);

            newSubassembly.CenterOfMass = CombinedCenterOfMass(newSubassembly);
            return(newSubassembly);
        }
示例#24
0
        /// <summary>
        /// Evaluates the subassemly.
        /// </summary>
        /// <param name="subassemblyNodes">The subassembly nodes - all the nodes in the combined install action.</param>
        /// <param name="optNodes">The subset of nodes that represent one of the two parts in the install step.</param>
        /// <param name="sub">The sub is the class that is then tied into the treequence.</param>
        /// <returns>System.Double.</returns>
        public double EvaluateSub(designGraph graph, HashSet <Component> subassemblyNodes, List <Component> optNodes,
                                  HashSet <int> validDirs, out SubAssembly sub)
        {
            var rest = subassemblyNodes.Where(n => !optNodes.Contains(n)).ToList();

            sub = Update(optNodes, rest);
            var connectingArcs =
                graph.arcs.Where(a => a is Connection)
                .Cast <Connection>()
                .Where(a => ((optNodes.Contains(a.To) && rest.Contains(a.From)) ||
                             (optNodes.Contains(a.From) && rest.Contains(a.To))))
                .ToList();
            var insertionDirections = InsertionDirectionsFromRemovalDirections(sub, optNodes, validDirs);
            var minDis = double.PositiveInfinity;
            var bestInstallDirection = new[] { 0.0, 0.0, 0.0 };

            foreach (var dir in insertionDirections)
            {
                var dis = DetermineDistanceToSeparateHull(sub, dir);
                if (dis >= minDis)
                {
                    continue;
                }
                minDis = dis;
                bestInstallDirection = dir;
            }
            sub.Install.InstallDirection = bestInstallDirection;
            sub.Install.InstallDistance  = minDis;
            // I need to add InstallationPoint also
            var install = new[] { rest, optNodes };

            if (EitherRefOrMovHasSeperatedSubassemblies(install, subassemblyNodes))
            {
                return(-1);
            }
            var moivingnames = sub.Install.Moving.PartNames;
            var refnames     = sub.Install.Reference.PartNames;
            var movingnodes  = subassemblyNodes.Where(n => moivingnames.Contains(n.name)).ToList();
            var refnodes     = subassemblyNodes.Where(n => refnames.Contains(n.name)).ToList();

            /////time
            sub.Install.Time = 0;
            EvaluateSubFirstThreeTime(sub, refnodes, movingnodes, minDis, out sub.Install.Time, out sub.Install.TimeSD, out sub.Secure.Time, out sub.Secure.TimeSD);
            if (sub.Install.Time < 0)
            {
                sub.Install.Time = 0.5;
            }
            ///////stability

            //assembly gravity direction is oppositve to install directon
            var Gravitydir = bestInstallDirection.multiply(-1);


            var stbility1 =
                Stabilityfunctions.EvaluateSubStability(Program.AssemblyGraph, refnodes, movingnodes, sub, Gravitydir);

            if (refnodes.Count == 1)
            {
                stbility1 = -1;
            }
            var stbility2 =
                Stabilityfunctions.EvaluateSubStability(Program.AssemblyGraph, movingnodes, refnodes, sub, Gravitydir);

            if (movingnodes.Count == 1)
            {
                stbility2 = -1;
            }
            var stbility = stbility1 + stbility2;

            sub.InternalStabilityInfo.Totalsecore = stbility;

            sub.Secure.Fasteners = ConnectingArcsFastener(connectingArcs, subassemblyNodes, optNodes);



            return(1);
        }
示例#25
0
        public static void EvaluateSubFirstThreeTime(SubAssembly sub, List <Component> refnodes, List <Component> movingnodes,
                                                     double olpdis, out double totaltime, out double totalSD, out double securetime, out double securesd)
        {
            var inputunitscaler = Program.MeshMagnifier / 1000;//magnifier translate unit to cm
            var movingsolids    = new List <TessellatedSolid>();
            var referencesolids = new List <TessellatedSolid>();
            var movingvertex    = new List <Vertex>();

            var counter = 10e6;

            ///////
            ///moving
            ///////
            foreach (var n in movingnodes)
            {
                movingsolids.Add(Program.Solids[n.name][0]); //cheange bbbbb class
            }
            foreach (var v in sub.Install.Moving.CVXHull.Vertices)
            {
                movingvertex.Add(v);
            }
            var movingOBB = OBB.BuildUsingPoints(movingvertex);

            //  var movingOBB = OBB.BuildUsingPoints(movingvertex);
            var lengths = new double[]
            {
                StarMath.norm1(movingOBB.CornerVertices[0].Position.subtract(movingOBB.CornerVertices[1].Position)),
                StarMath.norm1(movingOBB.CornerVertices[2].Position.subtract(movingOBB.CornerVertices[1].Position)),
                StarMath.norm1(movingOBB.CornerVertices[0].Position.subtract(movingOBB.CornerVertices[4].Position)),
            };
            var    lmax          = lengths.Max() / inputunitscaler;                                                    //mm
            var    lmin          = lengths.Min() / inputunitscaler;                                                    //mm
            double lmid          = lengths.Average() / inputunitscaler * 3 - lmax - lmin;
            var    movingweight  = Math.Log(sub.Install.Moving.Mass / inputunitscaler / Math.Pow(inputunitscaler, 3)); //in g ???????????
            var    OBBvolue      = Math.Log(movingOBB.Volume / 1000 / Math.Pow(inputunitscaler, 3));                   //cm^3
            var    OBBmaxsurface = Math.Log(lmax * lmid / 1000);
            var    OBBminsurface = Math.Log(lmin * lmid / 1000);
            /////
            /// distance TBD
            var movingdistance = 50;//cm
            var movingdis      = Math.Log(movingdistance);
            var movinginput    = new double[5] {
                movingweight, OBBvolue, OBBmaxsurface, OBBminsurface, movingdis
            };

            sub.MoveRoateModelInputs = OnlineGPupdating.RowtoMatrix(movinginput);
            //    Log ( weight, OOBvol OBB, maxf OBB, minf moving, distance  )all in mmgs unit system
            double movingtime = 0.0;
            double movingSD   = 0.0;

            CalculateAssemblyTimeAndSD.GetTimeAndSD(sub, movinginput, "moving", out movingtime, out movingSD);

            // Program.allmtime.Add(movingtime);
            ///////
            ///install
            ///////
            var allolpfs = BlockingDetermination.OverlappingSurfaces.FindAll(
                s =>
                (movingnodes.Any(n => n.name.Equals(s.Solid1.Name))) &&
                (refnodes.Any(n => n.name.Equals(s.Solid2.Name)))
                ||
                (movingnodes.Any(n => n.name.Equals(s.Solid2.Name))) &&
                (refnodes.Any(n => n.name.Equals(s.Solid1.Name)))
                );
            double olpfeatures = 0.0;

            for (int i = 0; i < allolpfs.Count; i++)
            {
                olpfeatures += allolpfs[i].Overlappings.Count; ////no alignment features for now;
            }
            if (olpfeatures == 0)
            {
                olpfeatures = 0.3;
            }
            var logOverlappingDist = Math.Log(olpdis / inputunitscaler);

            if (double.IsInfinity(logOverlappingDist))
            {
                logOverlappingDist = 1e-6;
            }
            var installinput = new double[6] {
                movingweight, OBBvolue, OBBmaxsurface, OBBminsurface, logOverlappingDist, Math.Log(olpfeatures)
            };

            sub.InstallModelInputs = OnlineGPupdating.RowtoMatrix(installinput);
            double installtime = 0;
            double instalSD    = 0;

            CalculateAssemblyTimeAndSD.GetTimeAndSD(sub, installinput, "install", out installtime, out instalSD);
            //Program.allitime.Add(installtime);
            ///////
            ///secure
            ///////
            securetime = 0.0;
            securesd   = 0.0;
            if (sub.Secure.Fasteners != null)
            {
                foreach (var f in sub.Secure.Fasteners)
                {
                    double eachseucretime = 0;
                    double eachsecureSD   = 0;
                    var    secureinput    = new double[6];
                    if (f.SecureModelInputs == null)
                    {
                        var OBBmax          = (f.Diameter / inputunitscaler) * (f.OverallLength / inputunitscaler);
                        var OBBmin          = (f.Diameter / inputunitscaler) * (f.Diameter / inputunitscaler);
                        var numberofthreads = f.NumberOfThreads;
                        if (numberofthreads == 0)
                        {
                            numberofthreads = 10;
                        }
                        var insertdistance = f.EngagedLength / inputunitscaler * 0.5;
                        if (insertdistance == 0)
                        {
                            insertdistance = numberofthreads * 0.25;
                        }
                        var nut  = 1;
                        var tool = 2;
                        if (f.Nuts != null)
                        {
                            nut = 2;
                        }
                        secureinput = new double[6] {
                            Math.Log(OBBmax / 1000), Math.Log(OBBmin / 1000), Math.Log(numberofthreads), Math.Log(insertdistance), nut, tool
                        };
                        f.SecureModelInputs = OnlineGPupdating.RowtoMatrix(secureinput);
                    }
                    else
                    {
                        secureinput = OnlineGPupdating.MatrixtoRow(f.SecureModelInputs);
                    }
                    CalculateAssemblyTimeAndSD.GetTimeAndSD(sub, secureinput, "s", out eachseucretime, out eachsecureSD);
                    securetime += eachseucretime;
                    securesd   += eachsecureSD;
                    f.Time      = eachseucretime;
                    f.TimeSD    = eachsecureSD;
                    //   if (eachseucretime > 30)
                    //   {
                    //       var sssss = 1;
                    //   }
                    ////   if (securetime != 0)
                    //      // Bridge.gpsecuretime.Add(eachseucretime);
                }
            }
            if (installtime < 0)
            {
                installtime = 0.5;
            }
            if (movingtime < 0)
            {
                movingtime = 0.5;
            }
            sub.MoveRoate.Time   = movingtime;
            sub.MoveRoate.TimeSD = movingSD;
            totalSD            = instalSD + movingSD;
            sub.Install.Time   = installtime;
            sub.Install.TimeSD = totalSD;
            sub.Secure.Time    = securetime;
            sub.Secure.TimeSD  = securesd;
            totaltime          = installtime + movingtime;

            if (movingtime > 2.9 && movingtime < 3.01)
            {
                var sss = 1;
            }
            if (installtime > 2.9 && installtime < 3.01)
            {
                var sss = 1;
            }


            // Bridge.gpinstalltime.Add(installtime);
            //  Bridge.gpmovingtime.Add(movingtime);
        }
        internal static AssemblySequence Run(designGraph graph, Dictionary <string, List <TessellatedSolid> > solids,
                                             List <int> globalDirPool, bool DoEstimate = false)
        {
            Constants.Values = new Constants();
            //if (Bridge.RestartBoolean) ClearEveryThing();
            Graph             = graph;
            AssemblyEvaluator = new EvaluationForBinaryTree(solids);
            DirPool           = globalDirPool;
            //Updates.UpdateGlobalDirections(DirPool);
            Estimate = DoEstimate;
            TimeEstmCounter++;
            TimeEstm++;

            SubAssembly tree  = null;
            var         watch = new Stopwatch();

            watch.Start();

            /*
             *          InitializeMemoBoosted();
             *          var best = F(out tree, new HashSet<Component>(Graph.nodes.Cast<Component>()));
             */
#if SerialDebug
            InitializeMemo();
            var best = F(out tree, new HashSet <Component>(Graph.nodes.Cast <Component>()));
#else
            Task.Factory.StartNew(() => InitializeMemoBoosted());
            Task.Factory.StartNew(() =>
            {
                var best = F(out tree, new HashSet <Component>(Graph.nodes.Cast <Component>()));
            });
            Task.WaitAll();
#endif
            watch.Stop();
            //var index = 0;
            //foreach (var component in Graph.nodes.Cast<Component>())
            //{
            //    Node2Int[component.name] = index++; //for use with PrintTree
            //}
            //redo:


            /*var frozen = new HashSet<Component>();
             * foreach (var n in tree.Install.Moving.PartNames)
             *  frozen.Add((Component) Graph.nodes.First(nod => nod.name == n));
             * FrozenSequence.Add(frozen);
             *
             * foreach (var seq in FrozenSequence)
             * {
             *  var last = Graph.addHyperArc(seq.Cast<node>().ToList());
             *  last.localLabels.Add(DisConstants.gSCC);
             * }*/
            // when the code is running again with frozen subassemblies, keep the memo of each frozen sub,
            // the ones with and 2 nodeas and and remove the rest.
            //UpdateTheMemo();
            //goto redo;
            //Console.WriteLine("Best assembly time found: " + Best);
            //for (int i = 1; i <= Graph.nodes.Count; i++)
            //	Console.WriteLine(i+" "+Count[i]);
            //PrintTree(Tree);
            return(new AssemblySequence {
                Subassemblies = new List <SubAssembly> {
                    tree
                }
            });
            //return Tree;
        }