Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/06/12 16:11:36 (13 years ago)
Author:
svonolfe
Message:

Adapted MPI operators (#1542)

Location:
branches/MPI/HeuristicLab.MPIAlgorithmRunner/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/MPI/HeuristicLab.MPIAlgorithmRunner/3.3/HeuristicLab.MPIAlgorithmRunner-3.3.csproj

    r7205 r7566  
    115115      <Private>False</Private>
    116116    </Reference>
     117    <Reference Include="HeuristicLab.Operators-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL" />
    117118    <Reference Include="HeuristicLab.Optimization-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    118119      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Optimization-3.3.dll</HintPath>
  • branches/MPI/HeuristicLab.MPIAlgorithmRunner/3.3/Program.cs

    r7544 r7566  
    3333using HeuristicLab.Core;
    3434using System.Diagnostics;
     35using HeuristicLab.Common;
     36using System.IO;
    3537
    3638namespace HeuristicLab.MPIAlgorithmRunner {
     
    4143      if (args.Length == 2) {
    4244        string fileName = args[0];
    43         string resultName = args[1];
    44 
    45         using (new MPI.Environment(ref args)) {
    46           if (MPI.Communicator.world.Rank != 0) {
    47             Program p = new Program();
    48             p.StartAlgorithm(fileName, resultName + MPI.Communicator.world.Rank + ".hl");
     45        int calcTime;
     46        if (int.TryParse(args[1], out calcTime)) {
     47         using (new MPI.Environment(ref args)) {
     48            if (MPI.Communicator.world.Rank != 0) {
     49              Program p = new Program();
     50              p.StartAlgorithm(fileName,calcTime);
     51            }
     52          }                     
     53        } else {
     54          string resultName = args[1];
     55
     56          using (new MPI.Environment(ref args)) {
     57            if (MPI.Communicator.world.Rank != 0) {
     58              Program p = new Program();
     59              p.StartAlgorithm(fileName, resultName + MPI.Communicator.world.Rank + ".hl");
     60            }
    4961          }
    50         }
     62        }       
    5163      } else {
    5264        using (new MPI.Environment(ref args)) {
     
    192204      sw.Start();
    193205
    194      /* Thread.Sleep(10000);     
    195       Thread t = new Thread(delegate() {
    196         while (true) {
    197           if (alg.ExecutionState == Core.ExecutionState.Started) {
    198             alg.Pause();
    199 
    200             while (alg.ExecutionState == Core.ExecutionState.Started)
    201               Thread.Sleep(100);
    202 
    203             if (alg.Results.ContainsKey("Best valid Solution Distance")) {
    204               Console.WriteLine("BestDistance: " + alg.Results["Best valid Solution Distance"].Value.ToString());
    205             }
    206 
    207             if (alg.Results.ContainsKey("Best valid Solution Vehicles")) {
    208               Console.WriteLine("BestVehicles: " + alg.Results["Best valid Solution Vehicles"].Value.ToString());
    209             }
    210 
    211             XmlGenerator.Serialize(alg, resultName);
    212             alg.Start();
     206      if (MPI.Communicator.world.Rank == 1) {
     207        Thread.Sleep(10000);
     208        Thread t = new Thread(delegate() {
     209          while (true) {
     210            if (alg.ExecutionState == Core.ExecutionState.Started) {
     211              alg.Pause();
     212
     213              while (alg.ExecutionState == Core.ExecutionState.Started)
     214                Thread.Sleep(100);
     215
     216              if (alg.Results.ContainsKey("Best valid VRP Solution Distance")) {
     217                Console.WriteLine("BestDistance: " + alg.Results["Best valid VRP Solution Distance"].Value.ToString());
     218              }
     219
     220              if (alg.Results.ContainsKey("Best valid VRP Solution VehicleUtilization")) {
     221                Console.WriteLine("BestVehicles: " + alg.Results["Best valid VRP Solution VehicleUtilization"].Value.ToString());
     222              }
     223
     224              XmlGenerator.Serialize(alg, resultName);
     225              alg.Start();
     226            }
     227
     228            Thread.Sleep(300000);
    213229          }
    214 
    215           Thread.Sleep(300000);
    216         }
    217       });
    218       t.IsBackground = true;
    219       t.Start();*/
     230        });
     231        t.IsBackground = true;
     232        t.Start();
     233      }
    220234
    221235      waitHandle.WaitOne();
     
    225239      Console.WriteLine("TIME: " + sw.ElapsedMilliseconds + "ms");
    226240
    227       if (alg.Results.ContainsKey("Best valid Solution Distance") && alg.Results.ContainsKey("Best valid Solution Vehicles")) {
    228         Console.WriteLine("BestDistance: " + alg.Results["Best valid Solution Distance"].Value.ToString() + ", " +
    229                           "BestVehicles: " + alg.Results["Best valid Solution Vehicles"].Value.ToString());
     241      if (alg.Results.ContainsKey("Best valid VRP Solution Distance") && alg.Results.ContainsKey("Best valid VRP Solution VehicleUtilization")) {
     242        Console.WriteLine("BestDistance: " + alg.Results["Best valid VRP Solution Distance"].Value.ToString() + ", " +
     243                          "BestVehicles: " + alg.Results["Best valid VRP Solution VehicleUtilization"].Value.ToString());
    230244      }
    231245
     
    236250      waitHandle.Set();
    237251    }
     252
     253    public void StartAlgorithm(string fileName, int calculationTime) {
     254      IAlgorithm alg = XmlParser.Deserialize<HeuristicLab.Optimization.IAlgorithm>(fileName);
     255      IOperator breakpoint = ((alg.Parameters["Analyzer"] as IValueParameter).Value as IOperator);
     256
     257      waitHandle.Reset();
     258
     259      alg.Start();
     260
     261      Thread.Sleep(calculationTime);
     262
     263      if (alg.ExecutionState == ExecutionState.Started) {
     264        waitHandle.Reset();
     265        alg.Paused += new EventHandler(alg_Paused);
     266        breakpoint.Breakpoint = true;
     267
     268        waitHandle.WaitOne();
     269
     270        breakpoint.Breakpoint = false;
     271        alg.Paused -= new EventHandler(alg_Paused);
     272      }
     273
     274      Mutex mutex = new Mutex(false, "ResultFile");
     275      mutex.WaitOne();
     276      Console.WriteLine("SERIALIZING");
     277      XmlGenerator.Serialize(alg, fileName);
     278      MPI.Communicator.world.Abort(0);
     279    }
     280
     281    void alg_Paused(object sender, EventArgs e) {
     282      waitHandle.Set();
     283    }
    238284  }
    239285}
Note: See TracChangeset for help on using the changeset viewer.