コード例 #1
0
 public void FillGrid(Grid g, FillOptions options)
 {
     using (var bitmapWrapper = new BmpPixelSnoop(drawArea))
         using (var textureWrapper = options.Texture != null ? new BmpPixelSnoop(options.Texture) : null)
             Parallel.ForEach(g.GetPolygons(), t => AlgorithmUtils.FillPolygon(t, options, bitmapWrapper, textureWrapper));
     //g.GetPolygons().ForEach(t => AlgorithmUtils.FillPolygon(t, options, bitmapWrapper, textureWrapper));
 }
コード例 #2
0
 /// <summary>
 /// returns a list of normalized values for the doubles in [startIndex, doubles.count]
 /// </summary>
 /// <param name="startIndex"></param>
 /// <returns></returns>
 public List <double> getNormalizedValues(int startIndex = 0)
 {
     double[] vals = new double[length - startIndex];
     for (int i = startIndex; i < length; ++i)
     {
         vals[i - startIndex] = this[i];
     }
     return(AlgorithmUtils.getNormalizedValues(vals));
 }
コード例 #3
0
                /// <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);
                }
コード例 #4
0
 /// <summary>
 /// assumes all values are in [0,1], and returns a vector of values with a sum of 1.
 /// Example: [0.5,0.5] -> [0.5,0.25,0.25]
 /// </summary>
 /// <returns></returns>
 public List <Double> getNormalizedValues()
 {
     //List<Double> res = new List<double>();
     //double remaining = 1;
     //for(int i = 0 ; i < count(); ++i)
     //{
     //    res.Add(remaining * this[i]);
     //    remaining -= res.Last();
     //}
     //res.Add(remaining);
     //return res;
     return(AlgorithmUtils.getNormalizedValues(val));
 }
コード例 #5
0
        private static Func <int, Func <string, Func <CryptoMode, string> > > ProcessFunc() => key => message => mode =>
        {
            var sbRet    = new StringBuilder();
            var alphabet = AlphabetDictionaryGenerator.Generate();

            foreach (var c in message)
            {
                var res = AlgorithmUtils.GetAlphabetPositionFunc()
                              (alphabet[c]) /*char position*/
                              (key)
                              (mode);       /*encryption algorithm mode*/

                sbRet.Append(alphabet.Keys.ElementAt(res % 26));
            }

            return(sbRet.ToString());
        };
コード例 #6
0
ファイル: AssertionsDemo.cs プロジェクト: skirov/TA-CSharp
    public static void Main()
    {
        int[] arr = new int[] { 3, -1, 15, 4, 17, 2, 33, 0 };

        Console.WriteLine("arr = [{0}]", string.Join(", ", arr));
        AlgorithmUtils.SelectionSort(arr);
        Console.WriteLine("sorted = [{0}]", string.Join(", ", arr));

        AlgorithmUtils.SelectionSort(new int[0]); // Test sorting empty array
        AlgorithmUtils.SelectionSort(new int[1]); // Test sorting single element array

        Console.WriteLine(AlgorithmUtils.BinarySearch(arr, -1000));
        Console.WriteLine(AlgorithmUtils.BinarySearch(arr, 0));
        Console.WriteLine(AlgorithmUtils.BinarySearch(arr, 17));
        Console.WriteLine(AlgorithmUtils.BinarySearch(arr, 10));
        Console.WriteLine(AlgorithmUtils.BinarySearch(arr, 1000));
    }
コード例 #7
0
        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);
        }
コード例 #8
0
                /// <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));
                }
コード例 #9
0
 public void Reduce(Options options)
 {
     originalBox.Image = options.OriginalImage;
     reducedBox.Image  = AlgorithmUtils.ReduceColors(options, progressBar);
 }
コード例 #10
0
 private static Func <string, Func <string, Func <CryptoMode, string> > > ProcessFunc() => key => message => mode =>
 {
     key = key.ToString().ToLower().Replace(" ", "");
     key = DuplicateKeyFunc()(key)(message);
     return(AlgorithmUtils.Shift(message, key, mode, AlphabetDictionaryGenerator.Generate()));
 };
コード例 #11
0
 private static Func <string, Func <string, Func <CryptoMode, string> > > ProcessFunc() => key => message => mode =>
 {
     var k = DuplicateKeyFunc()(key)(message);
     return(AlgorithmUtils.Shift(message, k, mode, AlphabetDictionaryGenerator.Generate()));
 };