Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/10/17 23:19:11 (7 years ago)
Author:
abeham
Message:

#2457: worked on code for eurocast paper

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PerformanceComparison/ProblemInstanceIdentifier/Program.cs

    r14776 r15031  
    1212namespace ProblemInstanceIdentifier {
    1313  class Program {
     14    static void Main(string[] args) {
     15      //var instances = Get20DifferentClasses();
     16      var instances = GetSomeRandomInstances(50, 13);
     17
     18      /*var classes = instances.Select(InstanceDescriptor.FromProblemOnly).GroupBy(x => x.Cls);
     19      foreach (var cls in classes.OrderBy(x => x.Key)) {
     20        Console.WriteLine("{0};{1}", cls.Key, cls.Count());
     21      }*/
     22
     23      var prExplorer = new PathRelinkingExplorer() {
     24        LocalOptima = false,
     25        Paths = 200
     26      };
     27      var prOldExplorer = new PathRelinkingOldFeaturedExplorer() {
     28        LocalOptima = false,
     29        Paths = 200
     30      };
     31
     32      var prLocalExplorer = new PathRelinkingExplorer() {
     33        LocalOptima = true,
     34        Paths = 200
     35      };
     36      var prOldLocalExplorer = new PathRelinkingOldFeaturedExplorer() {
     37        LocalOptima = true,
     38        Paths = 200
     39      };
     40
     41      var memPrExplorer = new MemPRExplorer() {
     42        IncludeLocalSearch = false,
     43        Seconds = 10
     44      };
     45
     46      //var training = GenerateData(instances, prOldExplorer, parallel: true);
     47      //var standardizer = InstancesStandardizer.CreateAndApply(training);
     48      //var test = GenerateData(instances, prOldExplorer, parallel: true);
     49      //standardizer.Apply(test);
     50      //PrintMatchResult(Compare(training, test));
     51
     52      //Console.WriteLine("=== Path Relinking Walk ===");
     53      //ExploreMatching(instances,
     54      //new[] { 1, 5, 10, 20, 50, 100, 200 }.Select(x => new PathRelinkingExplorer() { LocalOptima = false, Paths = x }).ToArray(),
     55      //new[] { 1, 5, 10, 20, 50, 100, 200 }.Select(x => new PathRelinkingExplorer() { LocalOptima = false, Paths = x }).ToArray(),
     56      //parallel: true);
     57      //Console.WriteLine("=== Random Walk ===");
     58      //ExploreMatching(instances,
     59      //new[] { 300, 1500, 3000, 6000, 15000, 30000, 60000 }.Select(x => new RandomWalkExplorer() { Iterations = x }).ToArray(),
     60      //new[] { 300, 1500, 3000, 6000, 15000, 30000, 60000 }.Select(x => new RandomWalkExplorer() { Iterations = x }).ToArray(),
     61      //parallel: true);
     62      //Console.WriteLine("=== Adaptive Walk ===");
     63      //ExploreMatching(instances,
     64      //new[] { 300, 1500, 3000, 6000, 15000, 30000, 60000 }.Select(x => new AdaptiveWalkExplorer() { Iterations = x / 10, SampleSize = 10 }).ToArray(),
     65      //new[] { 300, 1500, 3000, 6000, 15000, 30000, 60000 }.Select(x => new AdaptiveWalkExplorer() { Iterations = x / 10, SampleSize = 10 }).ToArray(),
     66      //parallel: true);
     67      Console.WriteLine("=== Up/Down Walk ===");
     68      ExploreMatching(instances,
     69      new[] { 300, 1500, 3000, 6000, 15000, 30000, 60000 }.Select(x => new UpDownWalkExplorer() { Iterations = x / 10, SampleSize = 10 }).ToArray(),
     70      new[] { 300, 1500, 3000, 6000, 15000, 30000, 60000 }.Select(x => new UpDownWalkExplorer() { Iterations = x / 10, SampleSize = 10 }).ToArray(),
     71      parallel: true);
     72    }
     73
     74    private static List<QuadraticAssignmentProblem> GetSomeRandomInstances(int totalInstances, int seed) {
     75      var sync = new object();
     76      var provider = new OneSizeInstanceProvider();
     77      var instances = new List<QuadraticAssignmentProblem>();
     78      var random = new FastRandom(seed);
     79      Parallel.ForEach(provider.GetDataDescriptors().Shuffle(random), desc => {
     80        var qapData = provider.LoadData(desc);
     81        if (instances.Count >= totalInstances) return;
     82        var qap = new QuadraticAssignmentProblem();
     83        qap.Load(qapData);
     84        lock (sync) {
     85          if (instances.Count >= totalInstances) return;
     86          instances.Add(qap);
     87        }
     88      });
     89      return instances;
     90    }
     91
    1492    private static HashSet<string> selectedInstances = new HashSet<string>() {
    1593      "bur26a", "chr25a", "dre24", "els19", "esc32a", "had20", "kra32", "lipa30a", "lipa30b",
     
    1795      "RAND-S-6x6-36-25-AFFY-00_rand_rand_bl", "RAND-S-6x6-36-25-AFFY-00_rand_rand_ci"
    1896    };
    19     static void Main(string[] args) {
    20       var instances = Get20DifferentClasses();
    21       //var instances = GetSomeRandomInstances(50);
    22 
    23       /*var classes = instances.Select(InstanceDescriptor.FromProblemOnly).GroupBy(x => x.Cls);
    24       foreach (var cls in classes.OrderBy(x => x.Key)) {
    25         Console.WriteLine("{0};{1}", cls.Key, cls.Count());
    26       }*/
    27 
    28       var prExplorer = new PathRelinkingExplorer() {
    29         LocalOptima = false,
    30         Paths = 200
    31       };
    32       var prLocalExplorer = new PathRelinkingExplorer() {
    33         LocalOptima = true,
    34         Paths = 200
    35       };
    36       var memPrExplorer = new MemPRExplorer() {
    37         IncludeLocalSearch = false,
    38         Seconds = 10
    39       };
    40 
    41       var training = GenerateData(instances, prExplorer, parallel:true);
    42       var standardizer = InstancesStandardizer.CreateAndApply(training);
    43       var test = GenerateData(instances, prExplorer, parallel: false);
    44       standardizer.Apply(test);
    45       PrintMatchResult(Compare(training, test));
    46 
    47       ExploreMatching(instances, new [] { prLocalExplorer }, new [] { memPrExplorer });
    48     }
    49 
    50     private static List<QuadraticAssignmentProblem> GetSomeRandomInstances(int totalInstances) {
    51       var sync = new object();
    52       var provider = new OneSizeInstanceProvider();
    53       var instances = new List<QuadraticAssignmentProblem>();
    54       var random = new FastRandom(0);
    55       Parallel.ForEach(provider.GetDataDescriptors().Shuffle(random), desc => {
    56         var qapData = provider.LoadData(desc);
    57         if (qapData.Dimension < 25) return;
    58         if (instances.Count >= totalInstances) return;
    59         var qap = new QuadraticAssignmentProblem();
    60         qap.Load(qapData);
    61         lock (sync) {
    62           if (instances.Count >= totalInstances) return;
    63           instances.Add(qap);
    64         }
    65       });
    66       return instances;
    67     }
    68 
    6997    private static List<QuadraticAssignmentProblem> Get20DifferentClasses() {
    7098      var sync = new object();
     
    100128      };
    101129      if (parallel) {
    102         Parallel.ForEach(instances, body);
     130        Parallel.ForEach(instances.Select(x => (QuadraticAssignmentProblem)x.Clone()), body);
    103131      } else {
    104132        foreach (var qap in instances) body(qap);
     
    156184    private static void ExploreMatching(List<QuadraticAssignmentProblem> instances, InstanceExplorer[] trainingExplorers, InstanceExplorer[] testExporers, bool parallel = false) {
    157185      var sync = new object();
    158       var rand = new Random();
    159       var first = rand.Next();
    160       var second = rand.Next();
    161       while (first == second) second = rand.Next();
    162186
    163187      var knowledgeBase = new Dictionary<InstanceExplorer, Tuple<InstancesStandardizer, List<InstanceDescriptor>>>();
Note: See TracChangeset for help on using the changeset viewer.