// Private members void OnSolveTriggered(int[,] data) { Debug.Log("Recieved Data in Application"); Solver solver = new Solver(); solver.Init(data); nestedSolver = new NestedSolver(); nestedSolver.Init(solver, 1); nestedSolver.Solve(OnSolveCompleted, OnSolveFailed); EnableLoadingGear(true); }
public void Update() { if (runSolver) { if (!Solver.IsSolvingCompleted()) { Solver.UpdateSolve(); if (Solver.IsThereAnError()) { QDebug.LogWarning("<color=yellow>Error occured. reverting " + ID.ToString() + "</color>"); OnFailedCallback(); } } else if (Solver.IsSolvedFully()) { onCompletedCallback(); runSolver = false; } else { // its not solved fully // but solver is done if (solutions == null) { CreateSolutions(); } if (childSolver == null) { if (currentIndex >= solutions.Count) { if (ID == BASE_ID && deepSearchLevel < eDeepSearch.HARD) { deepSearchLevel++; QDebug.LogError("DEEP SEARCH Level Increased. Level :" + deepSearchLevel.ToString()); currentIndex = 0; solutions = null; return; } QDebug.LogWarning("<color=yellow>All iterations completed. reverting " + ID.ToString() + "</color>"); OnFailedCallback(); } else { if ((deepSearchLevel == eDeepSearch.EASY && ID > 3) || (deepSearchLevel == eDeepSearch.MEDIUM && ID > 5) ) { //if ( ID > 3 ) { QDebug.LogWarning("<color=yellow>For Simple search. reverting " + ID.ToString() + "</color>"); OnFailedCallback(); return; } } childSolver = new NestedSolver(); //Solver.PrintPotential("before clone potential"); Solver.Print("<b>before clone " + ID.ToString() + " (" + currentIndex.ToString() + "/" + solutions.Count.ToString() + ")</b>"); QDebug.LogWarning(string.Format("New try with ID:{0} at ( {1}, {2} ) -> {3}", ID, solutions[currentIndex].r, solutions[currentIndex].c, solutions[currentIndex].value)); if (solutions.Count == 0 || currentIndex >= solutions.Count) { QDebug.LogError("ERROR. " + currentIndex.ToString() + "/" + solutions.Count.ToString()); Solver.PrintPotential("before clone potential " + ID.ToString()); } Solver clonedSolved = Solver.Clone(); clonedSolved.InitClone(); childSolver.Init(clonedSolved, solutions[currentIndex].r, solutions[currentIndex].c, solutions[currentIndex].value, (ID + 1)); childSolver.Solve(OnChildSuccess, OnChildFailed); childSolver.Solver.Print("after clone " + ID.ToString()); Solver.PrintPotential("before clone potential " + ID.ToString()); childSolver.Solver.PrintPotential("after clone potential " + ID.ToString()); currentIndex++; } } } if (childSolver != null) { childSolver.Update(); } } }