public double Evaluate(AssemblyCandidate c, option opt, List <Component> rest, List <TessellatedSolid> solides)
        {
            // Set up moving and reference subassemblies
            var newSubAsm      = c.Sequence.Update(opt, rest, ConvexHullsForParts);
            var refNodes       = newSubAsm.Install.Reference.PartNames.Select(n => (Component)c.graph[n]).ToList();
            var movingNodes    = newSubAsm.Install.Moving.PartNames.Select(n => (Component)c.graph[n]).ToList();
            var install        = new[] { refNodes, movingNodes };
            var connectingArcs = c.graph.arcs.Cast <Connection>().Where(a => ((movingNodes.Contains(a.To) && refNodes.Contains(a.From)) ||
                                                                              (movingNodes.Contains(a.From) && refNodes.Contains(a.To))))
                                 .ToList();

            //if (connectingArcs.Count == 0) return -1;
            foreach (Connection a in connectingArcs)
            {
                Updates.RemoveRepeatedFasteners2(a, c.graph);
                c.graph.removeArc(a);
            }
            if (Updates.EitherRefOrMovHasSeperatedSubassemblies(install))
            {
                return(-1);
            }

            // Getting insertion point coordinates
            double insertionDistance;
            var    insertionDirection = FindPartDisconnectMovement(connectingArcs, refNodes, out insertionDistance);

            var firstArc       = connectingArcs[0];
            var i              = firstArc.localVariables.IndexOf(Constants.CLASH_LOCATION);
            var insertionPoint = (i == -1) ? new Vertex(new[] { 0.0, 0.0, 0.0 })
                : new Vertex(new[] { firstArc.localVariables[i + 1], firstArc.localVariables[i + 2], firstArc.localVariables[i + 3] });

            newSubAsm.Install.InstallDirection = StarMath.multiply(insertionDistance, insertionDirection);
            newSubAsm.Install.InstallPoint     = insertionPoint.Position;

            var travelDistance = 1;//m

            //PathDeterminationEvaluator.FindTravelDistance(newSubAsm, insertionDirection, insertionPoint);

            newSubAsm.Install.Time =
                timeEvaluator.EvaluateTimeAndSDForInstall(connectingArcs, travelDistance, insertionDistance, newSubAsm)[0];
            newSubAsm.Install.TimeSD =
                timeEvaluator.EvaluateTimeAndSDForInstall(connectingArcs, travelDistance, insertionDistance, newSubAsm)[1];
            c.f3 += newSubAsm.Install.Time;

            var movableparts = new List <Component>();

            //movableparts =

            //c.f4 += newSubAsm.Install.TimeSD;
            //c.f4 = timeEvaluator.EvaluateTimeOfLongestBranch(c.Sequence);
            if (double.IsNaN(insertionDirection[0]))
            {
                Console.WriteLine();
            }

            double evaluationScore = InitialEvaluation(newSubAsm, newSubAsm.Install.InstallDirection, refNodes, movingNodes, c, newSubAsm.Install.Time);

            Updates.UpdateChildGraph(c, install);
            return(evaluationScore);
        }
Пример #2
0
        internal static void ApplyChild(AssemblyCandidate child, option opt)
        {
            // The function removes hyperarcs with "SCC" or "Seperate" lables
            for (var i = 0; i < child.graph.hyperarcs.Count; i++)
            {
                var hy = child.graph.hyperarcs[i];
                if (hy.localLabels.Contains(DisConstants.SeperateHyperarcs) && hy.nodes.Any(n => opt.Nodes.Contains(n)))
                {
                    child.graph.removeHyperArc(hy);
                    i--;
                    continue;
                }
                if ((hy.localLabels.Contains(DisConstants.SeperateHyperarcs) &&
                     !hy.nodes.Any(n => opt.Nodes.Contains(n))) || hy.localLabels.Contains(DisConstants.SingleNode))
                {
                    continue;
                }

                if (!hy.localLabels.Contains(DisConstants.Removable)) // Maybe all of them contain "Removable"
                {
                    child.graph.removeHyperArc(hy);
                    i--;
                }
                else
                {
                    if (hy.localLabels.Contains(DisConstants.SCC))
                    {
                        hy.localLabels.Remove(DisConstants.SCC);
                    }
                }
            }
        }
Пример #3
0
        internal static void UpdateChildGraph(AssemblyCandidate c, List <Component>[] install)
        {
            // This is happening in Evaluation
            for (var j = 0; j < c.graph.hyperarcs.Count; j++)
            {
                var hy = c.graph.hyperarcs[j];
                if (hy.localLabels.Contains(DisConstants.SeperateHyperarcs) ||
                    hy.localLabels.Contains(DisConstants.SingleNode))
                {
                    continue;
                }
                c.graph.removeHyperArc(c.graph.hyperarcs[j]);
                j--;
            }

            foreach (var list in install)
            {
                c.graph.addHyperArc(list.Cast <node>().ToList());
                if (list.Count == 1)
                {
                    c.graph.hyperarcs[c.graph.hyperarcs.Count - 1].localLabels.Add(DisConstants.SingleNode);
                }
                else
                {
                    c.graph.hyperarcs[c.graph.hyperarcs.Count - 1].localLabels.Add(DisConstants.SeperateHyperarcs);
                }
            }
        }
        internal static List <AssemblyCandidate> Run(designGraph assemblyGraph, List <TessellatedSolid> solids, List <int> globalDirPool, List <TessellatedSolid> solides)
        {
            //DisassemblyDirections.Directions = TemporaryDirections();
            var solutions = new List <AssemblyCandidate>();

            assemblyEvaluator = new AssemblyEvaluator(solids);
            //Updates.UpdateGlobalDirections(globalDirPool);
            assemblyGraph.addHyperArc(assemblyGraph.nodes);
            var iniHy = assemblyGraph.hyperarcs[assemblyGraph.hyperarcs.Count - 1];

            iniHy.localLabels.Add(DisConstants.SeperateHyperarcs);

            var candidates         = new SortedList <List <double>, AssemblyCandidate>(new MO_optimizeSort());
            var found              = false;
            AssemblyCandidate goal = null;
            var ini = new AssemblyCandidate(new candidate(assemblyGraph, 1));

            candidates.Add(new List <double>(), ini);

            while (candidates.Count != 0 && !found)
            {
                var current = candidates.Values[0];
                candidates.Clear();
                if (isCurrentTheGoal(current))
                {
                    goal  = current;
                    found = true;
                    break;
                }
                var options = new List <option>();
                foreach (var cndDirInd in globalDirPool)
                {
                    foreach (
                        var seperateHy in
                        current.graph.hyperarcs.Where(h => h.localLabels.Contains(DisConstants.SeperateHyperarcs))
                        .ToList())
                    {
                        SCC.StronglyConnectedComponents(current.graph, seperateHy, cndDirInd);
                        //BoostedSCC.StronglyConnectedComponents(current.graph, seperateHy, cndDirInd);
                        var blockingDic = DBG.DirectionalBlockingGraph(current.graph, cndDirInd);
                        options.AddRange(OptionGeneratorPro.GenerateOptions(current.graph, seperateHy, blockingDic, options));
                    }
                }
                foreach (var opt in options)
                {
                    //var child = (AssemblyCandidate) current.copy();
                    //SearchProcess.transferLmappingToChild(child.graph, current.graph, opt);
                    //var rest = Updates.AddSecondHyperToOption(child, opt);
                    //Updates.ApplyChild(child, opt);
                    //if (assemblyEvaluator.Evaluate(child, opt, rest, solides) > 0)
                    //    candidates.Add(child.performanceParams, child);
                    //child.addToRecipe(opt);
                }
            }
            solutions.Add(goal);
            TemporaryFixingSequence(goal);
            return(solutions);
        }
Пример #5
0
        public static void doAssemblyPlanning(string dir)
        {
            state = new ProgramState();
            if (dir == "")
            {
                dir = ".";
            }
            if (serverMode)
            {
                ProgramState.Load(dir + slash + "intermediate" + slash + "ProgramState.xml", ref state);
            }
            else
            {
                ProgramState.Load(dir + slash + "bin" + slash + "intermediate" + slash + "ProgramState.xml", ref state);
            }
            LoadState();

            checkDirs();
            AssemblyGraph.RepairGraphConnections();


            //$ Adding this so that bounding box related functionalities still work
            BoundingGeometry.OrientedBoundingBoxDic = new Dictionary <TessellatedSolid, BoundingBox>();
            BoundingGeometry.BoundingCylinderDic    = new Dictionary <TessellatedSolid, BoundingCylinder>();
            BoundingGeometry.CreateOBB2(Solids);
            BoundingGeometry.CreateBoundingCylinder(Solids);

            PartitioningSolid.Partitions     = new Dictionary <TessellatedSolid, Partition[]>();
            PartitioningSolid.PartitionsAABB = new Dictionary <TessellatedSolid, PartitionAABB[]>();
            PartitioningSolid.CreatePartitions(Program.SimplifiedSolids);

            NonadjacentBlockingWithPartitioning.Run(AssemblyGraph, SolidsNoFastenerSimplified, globalDirPool);
            GraphSaving.SaveTheGraph(AssemblyGraph);
            Stabilityfunctions.GenerateReactionForceInfo(AssemblyGraph);
            var leapSearch = new LeapSearch();
            var solutions  = leapSearch.Run(AssemblyGraph, Solids, globalDirPool);

            OptimalOrientation.Run(solutions);
            var cand = new AssemblyCandidate()
            {
                Sequence = solutions
            };

            cand.SaveToDisk(state.inputDir + slash + "XML" + slash + "solution.xml");
            WorkerAllocation.Run(solutions);

            SaveState();
            if (serverMode)
            {
                state.Save(state.inputDir + slash + "intermediate" + slash + "ProgramState.xml");
            }
            else
            {
                state.Save(state.inputDir + slash + "bin" + slash + "intermediate" + slash + "ProgramState.xml");
            }
            Console.WriteLine("\n\nDone");
        }
Пример #6
0
        private static void Allocation(AssemblyCandidate candidate)
        {
            var    earliestEndingTime = EarliestEndingTimeCalculator(candidate);
            var    latestEndingTime   = LatestEndingTimeCalculator(candidate);
            double criticalTime;
            var    criticalPath   = CriticalPathFinder(earliestEndingTime, latestEndingTime, out criticalTime);
            var    availableTasks = new List <string>();

            while (availableTasks.Count > 0)
            {
            }
        }
Пример #7
0
        private static void Main(string[] args)
        {
            state = new ProgramState();
            SetInputArguments(state, args);
            LoadState();
            Solids = GetSTLs(state.inputDir);
            EnlargeTheSolid();

            AssemblyGraph = new designGraph();
            DisassemblyDirectionsWithFastener.RunGeometricReasoning(Solids);
            if (DetectFasteners)
            {
                DisassemblyDirectionsWithFastener.RunFastenerDetection(Solids, FastenersAreThreaded);
            }
            //SolidsNoFastener = Solids;
            SerializeSolidProperties();
            Console.WriteLine("\nPress enter once input parts table generated >>");


            Console.ReadLine();
            DeserializeSolidProperties();
            globalDirPool = DisassemblyDirectionsWithFastener.RunGraphGeneration(AssemblyGraph, SolidsNoFastener);
            //the second user interaction must happen here
            SaveDirections();
            var connectedGraph = false;

            while (!connectedGraph)
            {
                Console.WriteLine("\n\nPress enter once input directions generated >>");
                Console.ReadLine();
                LoadDirections();
                connectedGraph = DisassemblyDirectionsWithFastener.GraphIsConnected(AssemblyGraph);
            }


            NonadjacentBlockingWithPartitioning.Run(AssemblyGraph, SolidsNoFastenerSimplified, globalDirPool);
            GraphSaving.SaveTheGraph(AssemblyGraph);
            Stabilityfunctions.GenerateReactionForceInfo(AssemblyGraph);
            var leapSearch = new LeapSearch();
            var solutions  = leapSearch.Run(AssemblyGraph, Solids, globalDirPool);

            OptimalOrientation.Run(solutions);
            var cand = new AssemblyCandidate()
            {
                Sequence = solutions
            };

            cand.SaveToDisk(state.inputDir + "solution.xml");
            WorkerAllocation.Run(solutions);
            Console.WriteLine("\n\nDone");
            Console.ReadLine();
        }
Пример #8
0
 internal static List <Component> AddSecondHyperToOption(AssemblyCandidate child, option opt)
 {
     foreach (
         var sepHy in
         child.graph.hyperarcs.Where(
             a =>
             a.localLabels.Contains(DisConstants.SeperateHyperarcs) &&
             opt.Nodes.All(n => a.nodes.Contains(n))))         //
     {
         return(sepHy.nodes.Where(n => !opt.Nodes.Contains(n)).Cast <Component>().ToList());
     }
     return(null);
 }
        private static void TemporaryFixingSequence(AssemblyCandidate goal)
        {
            var subAsms = goal.Sequence.Subassemblies;

            for (var i = subAsms.Count - 1; i > 0; i--)
            {
                foreach (var sub in subAsms)
                {
                    if (sub.Install.Moving.PartNames.All(n => subAsms[i].PartNames.Contains(n)) &&
                        subAsms[i].PartNames.All(n => sub.Install.Moving.PartNames.Contains(n)))
                    {
                        sub.Install.Moving = subAsms[i];
                    }
                    if (sub.Install.Reference.PartNames.All(n => subAsms[i].PartNames.Contains(n)) &&
                        subAsms[i].PartNames.All(n => sub.Install.Reference.PartNames.Contains(n)))
                    {
                        sub.Install.Reference = subAsms[i];
                    }
                }
            }
        }
Пример #10
0
 private static Dictionary <string, double> LatestEndingTimeCalculator(AssemblyCandidate candidate)
 {
     throw new NotImplementedException();
 }
Пример #11
0
 protected static bool isCurrentTheGoal(AssemblyCandidate current)
 {
     return(current.graph.hyperarcs.Where(h => h.localLabels.Contains("Done")).Count() == 20);
 }
        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);
        }