/// <summary> /// assumes only 1 param is used /// </summary> public List <PointF> sample(double minParam, double maxParam, double sampleDiff) { List <PointF> res = new List <PointF>(); for (double currentSamp = minParam; currentSamp < maxParam; currentSamp += sampleDiff) { res.Add(new PointF((float)currentSamp, (float)Evaluate(AlgorithmUtils.getRepeatingValueList <double>(currentSamp, 1)))); } res.Add(new PointF((float)maxParam, (float)Evaluate(AlgorithmUtils.getRepeatingValueList <double>(maxParam, 1)))); return(res); }
public static List <List <ProcessOutput> > process(SimArguments args) { ParallelizationManager trdMgr = new ParallelizationManager(args); List <List <ProcessOutput> > res = new List <List <ProcessOutput> >(); Parallel.For(0, args.argFiles.Count, trdMgr.parallelArgFiles, fileIdx => { ArgFile af = args.argFiles[fileIdx]; AppSettings.WriteLogLine("Processing Arg File:" + af.FileName); // load graph file AGameGraph graph = null; AppSettings.WriteLogLine("loading graph..."); string graphVal = af.processParams[0][AppConstants.AppArgumentKeys.GRAPH_FILE.key]; Utils.Exceptions.ConditionalTryCatch <Exception>(() => { if (graphVal.EndsWith(FileExtensions.GRAPH_FILE)) { graph = AGameGraph.loadGraph(File.ReadAllLines(FileUtils.TryFindingFile(graphVal))); //graph = new GridGameGraph(af.processParams[0][AppConstants.AppArgumentKeys.GRAPH_FILE.key]); } else { graph = AGameGraph.loadGraph(graphVal); } }, (Exception ex) => { AppSettings.WriteLogLine("couldn't load graph file:" + ex.Message); }); AppSettings.WriteLogLine("graph loaded. processing..."); // populate output table (ValuesCount is the amount of different values from param file, each should have separate theory/sim/optimizer process) res.Add(AlgorithmUtils.getRepeatingValueList <ProcessOutput>(af.processParams.ValuesCount)); populateResults(res.Last(), af.processParams, trdMgr.parallelArgValues, trdMgr.parallelSimRuns, graph); }); return(res); }
/// <summary> /// TODO: current implementation is naive - consider simplifying the func, deriving, then /// finding max using numerical methods /// </summary> /// <param name="minX"></param> /// <param name="maxX"></param> /// <param name="sampleDiff"></param> /// <param name="findMax">if true, finds max Y. otherwise, find min Y</param> /// <returns></returns> public PointF findExtremePoint(float minX, float maxX, float sampleDiff, bool findMax = true) { Algorithms.OptimizedObj <float> bestP = new OptimizedObj <float>(); bestP.data = minX; bestP.value = float.NegativeInfinity; if (findMax) { for (float currentSamp = minX; currentSamp < maxX; currentSamp += sampleDiff) { bestP.setIfValueIncreases(currentSamp, Evaluate(AlgorithmUtils.getRepeatingValueList <double>(currentSamp, 1))); } } else { for (float currentSamp = minX; currentSamp < maxX; currentSamp += sampleDiff) { bestP.setIfValueDecreases(currentSamp, Evaluate(AlgorithmUtils.getRepeatingValueList <double>(currentSamp, 1))); } } return(new PointF((float)bestP.data, (float)bestP.value)); }