/// <summary> /// Solves a file and adds to the processing queue. /// </summary> private void SolveFileTop(string tName) { string file; lock ( FilesQueue ) { if (FilesQueue.Count == 0) { return; } else { file = FilesQueue.Dequeue( ); } } System.Console.WriteLine("\tfile is {0} on thread {1}.", file, tName); if (Solve) { Solution solution = null; StreamReader s = null; AlgorithmRunner ar; try { s = new StreamReader(new FileStream(file, FileMode.Open, FileAccess.Read)); ar = new AlgorithmRunner(s, Loader, "", new Metric(1), true, null, 0); solution = ar.Solve(null); s.Close( ); } catch (Exception e) { System.Console.WriteLine(e.Message); s.Close( ); return; } if (solution.Path.Cost < new Metric(MinPathLength) || solution.Path.Cost > new Metric(MaxPathLength) || solution.Algorithm.Expansions < AStarMinExpansion || solution.Algorithm.Expansions > AStarMaxExpansion) { return; } WriteToOut(file + " " + solution.Path.Cost); } else { WriteToOut(file + " 0"); } }
/// <summary> /// Handles the top of the processing queue. /// </summary> private void DoProcessingQueueTop(string tName) { ProcessingQueueElement pqe; lock ( ProcessingQueue ) { pqe = ProcessingQueue.Dequeue( ); } System.Console.WriteLine( "\tpqe is | cl={0} file={2} alg={1} | on thread {3}.", pqe.ComputationLimit, pqe.Algorithm, pqe.File, tName); Results Result; StreamReader s = null; try { Loader.LOS = LOS; s = new StreamReader(new FileStream(pqe.File, FileMode.Open, FileAccess.Read)); Result = new AlgorithmRunner(s, Loader, pqe.Algorithm, new Metric(Weight), true, null, Seed).Run(0, true, computationLimitCeilingRatio, pqe.Algorithm, pqe.ComputationLimit, new Metric(pqe.OptimalSolutionCost), pqe.File, Dynamic); if (Result.PathLength < pqe.OptimalSolutionCost - 0.1) { WriteToOut("Exception Occcurd Unexplained Solution Cost pqe is | cl=" + pqe.ComputationLimit + " file=" + pqe.File + " alg=" + pqe.Algorithm + " |"); } WriteToOut(Result.ToString( )); } catch (MaxPathLengthExceded E) { WriteToOut("Ceiling Solution Cost pqe is | cl=" + pqe.ComputationLimit + " file=" + pqe.File + " alg=" + pqe.Algorithm + " |"); WriteToOut(E.Results.ToString( )); } catch (Exception e) { WriteToOut("Exception Caught " + e.Message + " pqe is | cl=" + pqe.ComputationLimit + " file=" + pqe.File + " alg=" + pqe.Algorithm + " |"); System.Console.WriteLine(e.Message + e.StackTrace); } finally { if (s != null) { s.Close( ); } } }
/// <summary> /// Runs the demo mode. /// </summary> /// <param name="args"></param> public override void Run(string[] args) { if (Solve) { this.ParseArgs(args); } if (Demo.Equals("presentation")) { (vis as OpenGLStateVisualizer).Presentation(false, false, false); } else if (Demo.Equals("presentation-doors")) { (vis as OpenGLStateVisualizer).Presentation(true, true, false); } else if (Demo.Equals("presentation-questions")) { (vis as OpenGLStateVisualizer).Presentation(false, true, true); } else if (Demo.Equals("none")) { } try { Loader.LOS = LOS; var AR = new AlgorithmRunner(filestream, Loader, Algorithm, new Metric(Weight), false, vis, Seed); if (Solve) { var SOL = AR.Solve(null); OptimalPathLenth = SOL.Path.Cost; } AR.Resultss = Resultss; Results = AR.Run(refreshRate, false, 1000, Algorithm, computationLimit, OptimalPathLenth, file, Dynamic); System.Console.WriteLine(Results); } catch (PathNotFoundException) { System.Console.Out.WriteLine("Path Not Found"); } }
/// <summary> /// Solves a file and adds to the processing queue. /// </summary> private void SolveFileTop(string tName) { string file; lock ( FilesQueue ) { if (FilesQueue.Count == 0) { return; } else { file = FilesQueue.Dequeue( ); } } System.Console.WriteLine("\tfile is {0} on thread {1}.", file, tName); Solution solution = null; StreamReader s = null; try { s = new StreamReader(new FileStream(file, FileMode.Open, FileAccess.Read)); solution = new AlgorithmRunner(s, Loader, "", new Metric(Weight), true, null, Seed).Solve(Out); s.Close( ); } catch (Net.Mokon.Edu.Unh.CS.AI.Search.Algorithms.PathNotFoundException) { WriteToOut("No Path Posible " + file); s.Close( ); return; } catch (Exception e) { WriteToOut("AStar Exception " + e.Message + " for file " + file); s.Close( ); return; } if (solution.Path.Cost < new Metric(MinPathLength)) { WriteToOut("Min Path Length Violated " + file); return; } else if (solution.Path.Cost > new Metric(MaxPathLength)) { WriteToOut("Max Path Length Violated " + file); return; } else if (solution.Algorithm.Expansions < AStarMinExpansion) { WriteToOut("Min Expansions Violated " + file); return; } else if (solution.Algorithm.Expansions > AStarMaxExpansion) { WriteToOut("Max Expansions Violated " + file); return; } double OptimalSolutionCost = solution.Path.Cost.ToDouble( ); foreach (var Alg in Algorithms) { int computationLimit, clindex; for (computationLimit = computationLimitMin, clindex = 1; computationLimit < computationLimitMax; computationLimit = computationLimitMethod(computationLimit, clindex), clindex++) { ProcessingQueueElement e; e.Algorithm = Alg; e.File = file; e.OptimalSolutionCost = OptimalSolutionCost; e.ComputationLimit = computationLimit; lock ( ProcessingQueue ) { ProcessingQueue.Enqueue(e); } if (!IsRealTime(Alg)) { break; } } } }
/// <summary> /// Runs the demo mode. /// </summary> /// <param name="args"></param> public override void Run( string[] args ) { if ( Solve ) { this.ParseArgs( args ); } if ( Demo.Equals( "presentation" ) ) { ( vis as OpenGLStateVisualizer ).Presentation( false, false, false ); } else if ( Demo.Equals( "presentation-doors" ) ) { ( vis as OpenGLStateVisualizer ).Presentation( true, true, false ); } else if ( Demo.Equals( "presentation-questions" ) ) { ( vis as OpenGLStateVisualizer ).Presentation( false, true, true ); } else if ( Demo.Equals( "none" ) ) { } try { Loader.LOS = LOS; var AR = new AlgorithmRunner( filestream, Loader, Algorithm, new Metric( Weight ), false, vis, Seed ); if ( Solve ) { var SOL = AR.Solve( null ); OptimalPathLenth = SOL.Path.Cost; } AR.Resultss = Resultss; Results = AR.Run( refreshRate, false, 1000, Algorithm, computationLimit, OptimalPathLenth, file, Dynamic ); System.Console.WriteLine( Results ); } catch ( PathNotFoundException ) { System.Console.Out.WriteLine( "Path Not Found" ); } }
/// <summary> /// Solves a file and adds to the processing queue. /// </summary> private void SolveFileTop( string tName ) { string file; lock ( FilesQueue ) { if ( FilesQueue.Count == 0 ) { return; } else { file = FilesQueue.Dequeue( ); } } System.Console.WriteLine( "\tfile is {0} on thread {1}.", file, tName ); Solution solution = null; StreamReader s = null; try { Loader.LOS = LOS; s = new StreamReader( new FileStream( file, FileMode.Open, FileAccess.Read ) ); solution = new AlgorithmRunner( s, Loader, "", new Metric( Weight ), true, null, Seed ).Solve( Out ); s.Close( ); } catch ( PathNotFoundException ) { WriteToOut( "No Path Posible " + file ); s.Close( ); return; } catch ( Exception e ) { WriteToOut( "AStar Exception " + e.Message + " for file " + file ); s.Close( ); return; } if ( solution.Path.Cost < new Metric( MinPathLength ) ) { WriteToOut( "Min Path Length Violated " + file ); return; } else if ( solution.Path.Cost > new Metric( MaxPathLength ) ) { WriteToOut( "Max Path Length Violated " + file ); return; } else if ( solution.Algorithm.Expansions < AStarMinExpansion ) { WriteToOut( "Min Expansions Violated " + file ); return; } else if ( solution.Algorithm.Expansions > AStarMaxExpansion ) { WriteToOut( "Max Expansions Violated " + file ); return; } double OptimalSolutionCost = solution.Path.Cost.ToDouble( ); foreach ( var Alg in Algorithms ) { int computationLimit, clindex; for ( computationLimit = computationLimitMin, clindex = 1 ; computationLimit < computationLimitMax ; computationLimit = computationLimitMethod( computationLimit, clindex ), clindex++ ) { ProcessingQueueElement e; e.Algorithm = Alg; e.File = file; e.OptimalSolutionCost = OptimalSolutionCost; e.ComputationLimit = computationLimit; lock ( ProcessingQueue ) { ProcessingQueue.Enqueue( e ); } if ( !IsRealTime( Alg ) ) { break; } } } }
/// <summary> /// Handles the top of the processing queue. /// </summary> private void DoProcessingQueueTop( string tName ) { ProcessingQueueElement pqe; lock ( ProcessingQueue ) { pqe = ProcessingQueue.Dequeue( ); } System.Console.WriteLine( "\tpqe is | cl={0} file={1} alg={2} | on thread {3}.", pqe.ComputationLimit, pqe.Algorithm, pqe.File, tName ); Results Result; StreamReader s = null; try { Loader.LOS = LOS; s = new StreamReader( new FileStream( pqe.File, FileMode.Open, FileAccess.Read ) ); Result = new AlgorithmRunner( s, Loader, pqe.Algorithm, new Metric( Weight ), true, null, Seed ).Run( 0, true, computationLimitCeilingRatio, pqe.Algorithm, pqe.ComputationLimit, new Metric( pqe.OptimalSolutionCost ), pqe.File, Dynamic ); if ( Result.PathLength < pqe.OptimalSolutionCost - 0.1 ) { WriteToOut( "Unexplained Solution Cost pqe is | cl=" + pqe.ComputationLimit + " file=" + pqe.File + " alg=" + pqe.Algorithm + " |" ); } WriteToOut( Result.ToString( ) ); } catch ( MaxPathLengthExceded ) { WriteToOut( "Ceiling Solution Cost pqe is | cl=" + pqe.ComputationLimit + " file=" + pqe.File + " alg=" + pqe.Algorithm + " |" ); } catch ( Exception e ) { WriteToOut( "Exception Caught " + e.Message + " pqe is | cl=" + pqe.ComputationLimit + " file=" + pqe.File + " alg=" + pqe.Algorithm + " |" ); } finally { if ( s != null ) { s.Close( ); } } }
/// <summary> /// Solves a file and adds to the processing queue. /// </summary> private void SolveFileTop( string tName ) { string file; lock ( FilesQueue ) { if ( FilesQueue.Count == 0 ) { return; } else { file = FilesQueue.Dequeue( ); } } System.Console.WriteLine( "\tfile is {0} on thread {1}.", file, tName ); if ( Solve ) { Solution solution = null; StreamReader s = null; AlgorithmRunner ar; try { s = new StreamReader( new FileStream( file, FileMode.Open, FileAccess.Read ) ); ar = new AlgorithmRunner( s, Loader, "", new Metric( 1 ), true, null, 0 ); solution = ar.Solve( null ); s.Close( ); } catch ( Exception e ) { System.Console.WriteLine( e.Message ); s.Close( ); return; } if ( solution.Path.Cost < new Metric( MinPathLength )|| solution.Path.Cost > new Metric( MaxPathLength ) || solution.Algorithm.Expansions < AStarMinExpansion || solution.Algorithm.Expansions > AStarMaxExpansion ) { return; } WriteToOut( file + " " + solution.Path.Cost ); } else { WriteToOut( file + " 0" ); } }