Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/21/16 15:52:53 (7 years ago)
Author:
bwerth
Message:

#2592 several fixes and cleanups to adapt a more HeuristicLab-Code-Style + renaming of folders and Plugin

Location:
branches
Files:
2 edited
2 copied
1 moved

Legend:

Unmodified
Added
Removed
  • branches

    • Property svn:global-ignores set to
      bin
  • branches/MOCMAEvolutionStrategy/HeuristicLab.Algorithms.MOCMAEvolutionStrategy/3.3/Utilities.cs

    r14269 r14404  
    1 using System;
    2 using System.Collections.Generic;
    3 using System.Linq;
    4 using System.Text;
    5 using System.Threading.Tasks;
     1using System.Collections.Generic;
    62using HeuristicLab.Data;
    73
    84namespace HeuristicLab.Algorithms.MOCMAEvolutionStrategy {
    9   internal class Utilities {
     5  internal static class Utilities {
    106    internal static double[][] ToArray(DoubleMatrix m) {
    11       int i = m.Rows - 1;
    12       double[][] a = new double[i][];
     7      var i = m.Rows - 1;
     8      var a = new double[i][];
    139      for (i--; i >= 0; i--) {
    14         int j = m.Columns;
     10        var j = m.Columns;
    1511        a[i] = new double[j];
    1612        for (j--; j >= 0; j--) a[i][j] = m[i, j];
     
    1915    }
    2016
     17    public static int ArgMin<T>(IEnumerable<T> values, IComparer<T> comparer) {
     18      var mindex = 0;
     19      var min = default(T);
     20      var i = 0;
     21      foreach (var v in values) {
     22        if (mindex < 0 || comparer.Compare(v, min) < 0) {
     23          min = v;
     24          mindex = i;
     25        }
     26        i++;
     27      }
     28      return mindex;
     29
     30    }
     31    public static int ArgMax<T>(IEnumerable<T> values, IComparer<T> comparer) {
     32      var mindex = 0;
     33      var min = default(T);
     34      var i = 0;
     35      foreach (var v in values) {
     36        if (mindex < 0 || comparer.Compare(v, min) > 0) {
     37          min = v;
     38          mindex = i;
     39        }
     40        i++;
     41      }
     42      return mindex;
     43    }
     44    private class DoubleComparer : IComparer<double> {
     45      public int Compare(double x, double y) {
     46        return x.CompareTo(y);
     47      }
     48    }
     49    public static int ArgMax(this IEnumerable<double> values) {
     50      return ArgMax(values, new DoubleComparer());
     51    }
     52    public static int ArgMin(this IEnumerable<double> values) {
     53      return ArgMin(values, new DoubleComparer());
     54    }
    2155  }
    2256}
Note: See TracChangeset for help on using the changeset viewer.