private void AddEdge(Edge edge, ref bool done)
 {
     if (NodeExist(edge.NewCube) != null)
     {
         edge.NewCube = NodeExist(edge.NewCube);
     }
     if (DestinationGraph.NodeExist(edge.NewCube) != null)
     {
         DestinationGraph.IsGraphUnSolved = false;
         done = true;
     }
     Edges.Add(edge);
 }
Beispiel #2
0
        public void Execute()
        {
            try
            {
                var meetMiddleGraphArray = MeetMiddleGraphs.ToArray();

                while (IsSearching)
                {
                    // Excutes the destination graph multiple times (parallel execution)
                    var executeDesitnationGraph =
                        Task.Factory.StartNew(() => DestinationGraph.Execute())
                        .ContinueWith(prevTask => DestinationGraph.Execute())
                        .ContinueWith((prevTask) => DestinationGraph.Execute());
                    Task.WaitAny(executeDesitnationGraph);

                    executeDesitnationGraph =
                        Task.Factory.StartNew(() => DestinationGraph.Execute())
                        .ContinueWith(prevTask => DestinationGraph.Execute())
                        .ContinueWith((prevTask) => DestinationGraph.Execute());
                    Task.WaitAny(executeDesitnationGraph);

                    // If one of the nodes generated is solved break from this loop
                    if (!DestinationGraph.IsGraphUnSolved)
                    {
                        break;
                    }

                    var tmpTask  = Task.Factory.StartNew(() => meetMiddleGraphArray[0].Execute());
                    var tmpTask1 = Task.Factory.StartNew(() => meetMiddleGraphArray[1].Execute());
                    var tmpTask2 = Task.Factory.StartNew(() => meetMiddleGraphArray[2].Execute());
                    Task.WaitAll(tmpTask, tmpTask1, tmpTask2);

                    if (!DestinationGraph.IsGraphUnSolved)
                    {
                        break;
                    }

                    var tmpTask4 = Task.Factory.StartNew(() => meetMiddleGraphArray[3].Execute());
                    var tmpTask5 = Task.Factory.StartNew(() => meetMiddleGraphArray[4].Execute());
                    var tmpTask6 = Task.Factory.StartNew(() => meetMiddleGraphArray[5].Execute());
                    Task.WaitAll(tmpTask4, tmpTask5, tmpTask6);

                    if (!DestinationGraph.IsGraphUnSolved)
                    {
                        break;
                    }

                    /*
                     * Console.WriteLine(
                     *  string.Format("first " + " " + DestinationGraph.Nodes.Count() + " " +
                     *                meetMiddleGraphArray[0].Nodes.Count() + " " +
                     *                meetMiddleGraphArray[1].Nodes.Count() + " " +
                     *                meetMiddleGraphArray[5].Nodes.Count() + " " +
                     *                meetMiddleGraphArray[2].Nodes.Count() + " " +
                     *                meetMiddleGraphArray[3].Nodes.Count() + " " +
                     *                meetMiddleGraphArray[4].Nodes.Count()));
                     */
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }