Changeset 13312


Ignore:
Timestamp:
11/19/15 21:16:55 (3 years ago)
Author:
gkronber
Message:

#2069: merged r13210,r13225,r13266,r13309,r13311 from trunk to stable

Location:
stable
Files:
9 edited
3 copied

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Problems.GeneticProgramming.Views/3.3/HeuristicLab.Problems.GeneticProgramming.Views-3.3.csproj

    r12911 r13312  
    133133    <Compile Include="Plugin.cs" />
    134134    <Compile Include="Properties\AssemblyInfo.cs" />
     135    <Compile Include="Robocode\BattleRunnerDialog.cs">
     136      <SubType>Form</SubType>
     137    </Compile>
     138    <Compile Include="Robocode\BattleRunnerDialog.Designer.cs">
     139      <DependentUpon>BattleRunnerDialog.cs</DependentUpon>
     140    </Compile>
     141    <Compile Include="Robocode\CodeSymbolView.cs">
     142      <SubType>UserControl</SubType>
     143    </Compile>
     144    <Compile Include="Robocode\CodeSymbolView.Designer.cs">
     145      <DependentUpon>CodeSymbolView.cs</DependentUpon>
     146    </Compile>
     147    <Compile Include="Robocode\EnemyCollectionView.cs">
     148      <SubType>UserControl</SubType>
     149    </Compile>
     150    <Compile Include="Robocode\EnemyCollectionView.Designer.cs">
     151      <DependentUpon>EnemyCollectionView.cs</DependentUpon>
     152    </Compile>
     153    <Compile Include="Robocode\SolutionCodeView.cs">
     154      <SubType>UserControl</SubType>
     155    </Compile>
     156    <Compile Include="Robocode\SolutionCodeView.Designer.cs">
     157      <DependentUpon>SolutionCodeView.cs</DependentUpon>
     158    </Compile>
     159    <Compile Include="Robocode\SolutionProgramView.cs">
     160      <SubType>UserControl</SubType>
     161    </Compile>
     162    <Compile Include="Robocode\SolutionProgramView.Designer.cs">
     163      <DependentUpon>SolutionProgramView.cs</DependentUpon>
     164    </Compile>
    135165  </ItemGroup>
    136166  <ItemGroup>
     
    140170  </ItemGroup>
    141171  <ItemGroup>
     172    <ProjectReference Include="..\..\HeuristicLab.Collections\3.3\HeuristicLab.Collections-3.3.csproj">
     173      <Project>{958b43bc-cc5c-4fa2-8628-2b3b01d890b6}</Project>
     174      <Name>HeuristicLab.Collections-3.3</Name>
     175      <Private>False</Private>
     176    </ProjectReference>
     177    <ProjectReference Include="..\..\HeuristicLab.Common.Resources\3.3\HeuristicLab.Common.Resources-3.3.csproj">
     178      <Project>{0e27a536-1c4a-4624-a65e-dc4f4f23e3e1}</Project>
     179      <Name>HeuristicLab.Common.Resources-3.3</Name>
     180      <Private>False</Private>
     181    </ProjectReference>
    142182    <ProjectReference Include="..\..\HeuristicLab.Common\3.3\HeuristicLab.Common-3.3.csproj">
    143183      <Project>{A9AD58B9-3EF9-4CC1-97E5-8D909039FF5C}</Project>
  • stable/HeuristicLab.Problems.GeneticProgramming.Views/3.3/Plugin.cs.frame

    r13279 r13312  
    2828  [Plugin("HeuristicLab.Problems.GeneticProgramming.Views","Provides views for for genetic programming problems such as the artificial ant problem.", "3.3.0.$WCREV$")]
    2929  [PluginFile("HeuristicLab.Problems.GeneticProgramming.Views-3.3.dll", PluginFileType.Assembly)]
     30  [PluginDependency("HeuristicLab.Common","3.3")]
     31  [PluginDependency("HeuristicLab.Common.Resources","3.3")]
     32  [PluginDependency("HeuristicLab.Collections","3.3")]
    3033  [PluginDependency("HeuristicLab.Core","3.3")]
    3134  [PluginDependency("HeuristicLab.Core.Views","3.3")]
  • stable/HeuristicLab.Problems.GeneticProgramming/3.3/HeuristicLab.Problems.GeneticProgramming-3.3.csproj

    r13280 r13312  
    104104    </Reference>
    105105    <Reference Include="System.Drawing" />
     106    <Reference Include="System.IO.Compression" />
     107    <Reference Include="System.IO.Compression.FileSystem" />
    106108  </ItemGroup>
    107109  <ItemGroup>
     
    117119    <Compile Include="Plugin.cs" />
    118120    <Compile Include="Properties\AssemblyInfo.cs" />
     121    <Compile Include="robocode\EnemyCollection.cs" />
     122    <Compile Include="robocode\Grammar.cs" />
     123    <Compile Include="robocode\Interpreter.cs" />
     124    <Compile Include="robocode\Problem.cs" />
     125    <Compile Include="robocode\Solution.cs" />
     126    <Compile Include="robocode\Symbols\BooleanTreeNode.cs" />
     127    <Compile Include="robocode\Symbols\BooleanValue.cs" />
     128    <Compile Include="robocode\Symbols\CodeSymbol.cs" />
     129    <Compile Include="robocode\Symbols\Number.cs" />
     130    <Compile Include="robocode\Symbols\NumberTreeNode.cs" />
     131    <Compile Include="robocode\Symbols\ShotPower.cs" />
     132    <Compile Include="robocode\Symbols\ShotPowerTreeNode.cs" />
    119133  </ItemGroup>
    120134  <ItemGroup>
     
    122136    <None Include="Plugin.cs.frame" />
    123137    <None Include="Properties\AssemblyInfo.cs.frame" />
     138    <None Include="robocode\BattleObserver.class">
     139      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     140    </None>
     141    <None Include="robocode\BattleRunner.class">
     142      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     143    </None>
     144    <None Include="robocode\robocode.zip">
     145      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     146    </None>
    124147  </ItemGroup>
    125148  <ItemGroup>
     
    211234      <Install>true</Install>
    212235    </BootstrapperPackage>
     236  </ItemGroup>
     237  <ItemGroup>
     238    <Content Include="robocode\BattleRunner.java" />
    213239  </ItemGroup>
    214240  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  • stable/HeuristicLab.Problems.GeneticProgramming/3.3/Plugin.cs.frame

    r13280 r13312  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Text;
     23using System.IO;
     24using System.IO.Compression;
     25using System.Linq;
    2526using HeuristicLab.PluginInfrastructure;
    2627
     
    2829  [Plugin("HeuristicLab.Problems.GeneticProgramming","Provides implementations for genetic programming problems such as the artificial ant problem.", "3.3.0.$WCREV$")]
    2930  [PluginFile("HeuristicLab.Problems.GeneticProgramming-3.3.dll", PluginFileType.Assembly)]
     31  [PluginFile("Robocode/robocode.zip", PluginFileType.Data)]
     32  [PluginFile("Robocode/BattleRunner.class", PluginFileType.Data)]
     33  [PluginFile("Robocode/BattleObserver.class", PluginFileType.Data)]
    3034  [PluginDependency("HeuristicLab.Collections", "3.3")]
    3135  [PluginDependency("HeuristicLab.Common", "3.3")]
     
    4145  [PluginDependency("HeuristicLab.Random", "3.3")]
    4246  public class HeuristicLabProblemsGeneticProgrammingPlugin : PluginBase {
     47    public override void OnLoad() {
     48        base.OnLoad();
     49        if (!Directory.EnumerateDirectories(AppDomain.CurrentDomain.BaseDirectory, Path.Combine("Robocode", "libs"), SearchOption.TopDirectoryOnly).Any()) {
     50          ZipFile.ExtractToDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Path.Combine("Robocode", "robocode.zip")), AppDomain.CurrentDomain.BaseDirectory);
     51        }
     52      }
    4353  }
    4454}
  • stable/HeuristicLab.Problems.GeneticProgramming/3.3/robocode/Interpreter.cs

    r13210 r13312  
    3131namespace HeuristicLab.Problems.GeneticProgramming.Robocode {
    3232  public static class Interpreter {
     33
     34    // necessary for synchronization to guarantee that only one robocode program is executed at the same time
     35    // NOTE: this does not guarantee OS-wide mutual exclusion, but we ignore that for now
     36    private static readonly object syncRoot = new object();
     37
    3338    // TODO performance: it would probably be useful to implement the BattleRunner in such a way that we don't have to restart the java process each time, e.g. using console IO to load & run robots
    3439    public static double EvaluateTankProgram(ISymbolicExpressionTree tree, string path, EnemyCollection enemies, string robotName = null, bool showUI = false, int nrOfRounds = 3) {
     
    5661      javaCompileInfo.CreateNoWindow = true;
    5762
     63      // it's ok to compile multiple robocode programs concurrently
    5864      using (Process javaCompile = new Process()) {
    5965        javaCompile.StartInfo = javaCompileInfo;
     
    7076      }
    7177
    72       //parallel execution of multiple robocode instances can sometimes lead to a damaged robot.database
    73       var robotsDbFileName = Path.Combine(path, "robots", "robot.database");
    74       if (File.Exists(robotsDbFileName))
    75         File.Delete(robotsDbFileName);
    76 
    7778      ProcessStartInfo evaluateCodeInfo = new ProcessStartInfo();
    7879
     
    8990      evaluateCodeInfo.CreateNoWindow = true;
    9091
     92      // the robocode framework writes state to a file therefore parallel evaluation of multiple robocode programs is not possible yet.
    9193      double evaluation;
    92       using (Process evaluateCode = new Process()) {
    93         evaluateCode.StartInfo = evaluateCodeInfo;
    94         evaluateCode.Start();
    95         evaluateCode.WaitForExit();
    96 
    97         if (evaluateCode.ExitCode != 0) {
    98           DeleteRobotFiles(path, robotName);
    99           throw new Exception("Error running Robocode: " + evaluateCode.StandardError.ReadToEnd() + Environment.NewLine +
    100                               evaluateCode.StandardOutput.ReadToEnd());
    101         }
    102 
    103         try {
    104           string scoreString =
    105             evaluateCode.StandardOutput.ReadToEnd()
    106               .Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
    107               .Last();
    108           evaluation = Double.Parse(scoreString, CultureInfo.InvariantCulture);
    109         }
    110         catch (Exception ex) {
    111           throw new Exception("Error parsing score string: " + ex);
    112         }
    113         finally {
    114           DeleteRobotFiles(path, robotName);
     94      lock (syncRoot) {
     95        using (Process evaluateCode = new Process()) {
     96          evaluateCode.StartInfo = evaluateCodeInfo;
     97          evaluateCode.Start();
     98          evaluateCode.WaitForExit();
     99
     100          if (evaluateCode.ExitCode != 0) {
     101            DeleteRobotFiles(path, robotName);
     102            throw new Exception("Error running Robocode: " + evaluateCode.StandardError.ReadToEnd() +
     103                                Environment.NewLine +
     104                                evaluateCode.StandardOutput.ReadToEnd());
     105          }
     106
     107          try {
     108            string scoreString =
     109              evaluateCode.StandardOutput.ReadToEnd()
     110                .Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
     111                .Last();
     112            evaluation = Double.Parse(scoreString, CultureInfo.InvariantCulture);
     113          }
     114          catch (Exception ex) {
     115            throw new Exception("Error parsing score string: " + ex);
     116          }
     117          finally {
     118            DeleteRobotFiles(path, robotName);
     119          }
    115120        }
    116121      }
     
    222227
    223228    private static string InterpretCodeSymbol(ISymbolicExpressionTreeNode node) {
    224       var sy = node.Symbol as CodeSymbol;
    225       string code = string.Join(Environment.NewLine, node.Subtrees.Select(Interpret));
    226       return string.Format(
    227 @"{0}
    228 {1}
    229 {2}", sy.Prefix, code, sy.Suffix);
     229      var sy = (CodeSymbol)node.Symbol;
     230      string code = string.Join(Environment.NewLine, node.Subtrees.Select(Interpret));
     231      return sy.Prefix + Environment.NewLine + code + Environment.NewLine + sy.Suffix;
    230232    }
    231233
    232234    private static string InterpretBoolValue(ISymbolicExpressionTreeNode node) {
    233       var boolNode = node as BooleanTreeNode;
     235      var boolNode = (BooleanTreeNode)node;
    234236      return string.Format(NumberFormatInfo.InvariantInfo, "{0}", boolNode.Value).ToLower();
    235237    }
    236238
    237239    private static string InterpretNumber(ISymbolicExpressionTreeNode node) {
    238       var numberNode = node as NumberTreeNode;
     240      var numberNode = (NumberTreeNode)node;
    239241      return string.Format(NumberFormatInfo.InvariantInfo, "{0}", numberNode.Value);
    240242    }
    241243
    242244    private static string InterpetShotPower(ISymbolicExpressionTreeNode node) {
    243       var shotPowerNode = node as ShotPowerTreeNode;
     245      var shotPowerNode = (ShotPowerTreeNode)node;
    244246      return string.Format(NumberFormatInfo.InvariantInfo, "{0:E}", shotPowerNode.Value);
    245247    }
     
    306308      rhs = node.GetSubtree(1);
    307309
    308       return Interpret(lhs) + " == " + Interpret(rhs);
     310      return Interpret(lhs) + compSy + Interpret(rhs);
    309311    }
    310312
  • stable/HeuristicLab.Problems.GeneticProgramming/3.3/robocode/Symbols/ShotPowerTreeNode.cs

    r13210 r13312  
    6161      // mutation
    6262      var d = random.NextDouble() * 2.0 - 1.0;
    63       value = Math.Max(0.1, value + shakingFactor * d);
     63      value += shakingFactor * d;
     64      if (value < 0.1) value = 0.1;
     65      if (value > 3) value = 3;
    6466    }
    6567  }
  • stable/HeuristicLab.Tests

  • stable/HeuristicLab.Tests/HeuristicLab.Tests.csproj

    r13296 r13312  
    440440    <Compile Include="HeuristicLab-3.3\PluginLoader.cs" />
    441441    <Compile Include="HeuristicLab-3.3\Samples\AlpsSampleTest.cs" />
     442    <Compile Include="HeuristicLab-3.3\Samples\GPRobocodeSampleTest.cs" />
    442443    <Compile Include="HeuristicLab-3.3\Samples\OSESGriewankSampleTest.cs" />
    443444    <Compile Include="HeuristicLab-3.3\Samples\GAGroupingProblemSampleTest.cs" />
Note: See TracChangeset for help on using the changeset viewer.