- Timestamp:
- 05/23/13 16:14:55 (11 years ago)
- Location:
- branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL.Views/3.4
- Files:
-
- 15 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL.Views/3.4/CreateProblemMenuItem.cs
r9430 r9519 34 34 namespace HeuristicLab.Problems.GPDL.Views { 35 35 internal class CreateProblemMenuItem : HeuristicLab.MainForm.WindowsForms.MenuItem, IOptimizerUserInterfaceItemProvider { 36 private const string gpdlString = @"37 PROBLEM ArtificialAnt38 39 CODE <<40 public struct Point {41 public int x; public int y;42 public Point(int x, int y) {43 this.x = x;44 this.y = y;45 }46 };47 48 class World {49 50 private static string[] LosAltosTrail = new string[] {51 "" ### "",52 "" # .###.. "",53 "" # # # "",54 "" # # # "",55 "" ####.##### .############.. . "",56 "" # . # "",57 "" # # . "",58 "" # # . "",59 "" # # # "",60 "" . # . "",61 "" # . . "",62 "" # . # "",63 "" # # . "",64 "" # # ...###. "",65 "" . .#... # "",66 "" . . . "",67 "" # . . "",68 "" # # .#... "",69 "" # # # "",70 "" # # . "",71 "" # # . "",72 "" # . ...#. "",73 "" # . # "",74 "" ..##..#####. # # "",75 "" # # # "",76 "" # # # "",77 "" # # # "",78 "" # # # "",79 "" # # # "",80 "" # .#####....##.. # "",81 "" # # # "",82 "" . # # "",83 "" .####.. # "",84 "" #.# "",85 "" # "",86 "" # "",87 "" # "",88 "" # "",89 "" # "",90 "" # "",91 "" # "",92 "" ###### "",93 "" . "",94 "" # "",95 "" # "",96 "" # "",97 "" # "",98 "" # "",99 "" # "",100 "" #.. "",101 "" # "",102 "" # "",103 "" # "",104 "" # "",105 "" # "",106 "" .###### "",107 "" . "",108 "" # "",109 "" # "",110 "" # "",111 "" # "",112 "" # "",113 "" # "",114 "" # "",115 "" # "",116 "" # ""117 };118 private char[][] world = LosAltosTrail.Select(l=>l.ToArray()).ToArray();119 public int TotalFood = LosAltosTrail.Select(l=>l.Where(c=>c=='#').Count()).Sum();120 public int Width { get { return 100; } }121 public int Height { get { return 100; } }122 123 public void Reset() {124 world = LosAltosTrail.Select(l=>l.ToArray()).ToArray();125 }126 127 public bool FoodAt(Point p) {128 if(p.x < 0 || p.y < 0) return false;129 if(world.Length <= p.y) return false;130 if(world[p.y].Length <= p.x) return false;131 return world[p.y][p.x] == '#';132 }133 public void RemoveFoodAt(Point p) {134 if(world.Length < p.y) return;135 if(world[p.y].Length < p.x) return;136 world[p.y][p.x] = ' ';137 }138 }139 140 enum Direction {West, East, North, South};141 142 class AntState {143 public Point Position { get; set;}144 public int MaxSteps { get; set;}145 public Direction Direction { get; set; }146 public World World { get; set; }147 public int Steps { get; set; }148 public int FoodEaten { get; set; }149 150 public AntState() {151 Steps = 0;152 FoodEaten = 0;153 }154 155 public void TurnLeft() {156 Steps++;157 switch(Direction) {158 case Direction.West: Direction = Direction.South; break;159 case Direction.South: Direction = Direction.East; break;160 case Direction.East: Direction = Direction.North; break;161 case Direction.North: Direction = Direction.West; break;162 }163 }164 public void TurnRight() {165 Steps++;166 switch(Direction) {167 case Direction.West: Direction = Direction.North; break;168 case Direction.South: Direction = Direction.West; break;169 case Direction.East: Direction = Direction.South; break;170 case Direction.North: Direction = Direction.East; break;171 }172 }173 public void MoveForward() {174 Position = NextPosition;175 Steps++;176 if(World.FoodAt(Position)) {177 World.RemoveFoodAt(Position);178 FoodEaten++;179 }180 }181 public Point NextPosition {182 get {183 int x, y;184 switch(Direction) {185 case Direction.West:186 x = (Position.x + World.Width - 1) % World.Width;187 y = Position.y;188 return new Point(x, y);189 case Direction.South:190 x = Position.x;191 y = (Position.y + World.Height + 1) % World.Height;192 return new Point(x, y);193 case Direction.East:194 x = (Position.x + World.Width + 1) % World.Width;195 y = Position.y;196 return new Point(x, y);197 case Direction.North:198 x = Position.x;199 y = (Position.y + World.Height - 1) % World.Height;200 return new Point(x, y);201 }202 return new Point(-1,-1);203 }204 }205 }206 207 World CreateWorld() {208 var w = new World();209 Console.WriteLine(""Total food: ""+w.TotalFood);210 return w;211 }212 213 World world;214 >>215 INIT <<216 world = CreateWorld();217 >>218 219 NONTERMINALS220 Ant<<World world, AntState state>>.221 IfFoodAhead<<World world, AntState state>>.222 Prog2<<World world, AntState state>>.223 Prog3<<World world, AntState state>>.224 225 TERMINALS226 Left<<>> CONSTRAINTS .227 Right<<>> CONSTRAINTS .228 Move<<>> CONSTRAINTS .229 230 RULES231 Ant<<World world, AntState state>> =232 IfFoodAhead<<world, state>>233 | Prog2<<world, state>>234 | Prog3<<world, state>>235 | Left<<>> SEM << state.TurnLeft(); >>236 | Right<<>> SEM << state.TurnRight(); >>237 | Move<<>> SEM << state.MoveForward(); >>238 .239 240 IfFoodAhead<<World world, AntState state>> =241 SEM <<242 if(world.FoodAt(state.NextPosition)) {243 >>244 245 Ant<<world, state>> SEM << } else { >>246 Ant<<world, state>> SEM << } >>247 .248 249 Prog2<<World world, AntState state>> =250 Ant<<world, state>> Ant<<world, state>>251 .252 253 Prog3<<World world, AntState state>> =254 Ant<<world, state>> Ant<<world, state>> Ant<<world, state>>255 .256 257 258 MAXIMIZE /* could also use the keyword MINIMIZE here */259 <<260 world.Reset();261 var state = new AntState() {Position = new Point(0,0), MaxSteps=400, Direction=Direction.East, World = world};262 while(state.Steps < state.MaxSteps) {263 Ant(world, state);264 }265 return (double)state.FoodEaten;266 >>267 END ArtitificialAnt.268 ";269 270 271 36 public override string Name { 272 get { return " Create &Problem"; }37 get { return "Open &GPDL Editor"; } 273 38 } 274 39 public override IEnumerable<string> Structure { … … 294 59 295 60 public override void Execute() { 296 Utils.InstallModule("Utils", new Utils.ModuleMethodDelegate(Utils.UtilsMethod)); 297 Utils.InstallModule("Sets", new Utils.ModuleMethodDelegate(Sets.SetsMethod)); 298 Utils.InstallModule("Errors", new Utils.ModuleMethodDelegate(Errors.ErrorsMethod)); 299 300 Utils.InstallModule("GPDefLex", new Utils.ModuleMethodDelegate(GPDefLex.GPDefLexMethod)); 301 Utils.InstallModule("GPDefSem", new Utils.ModuleMethodDelegate(GPDefSem.GPDefSemMethod)); 302 Utils.InstallModule("GPDefSyn", new Utils.ModuleMethodDelegate(GPDefSyn.GPDefSynMethod)); 303 304 // --- initialize modules --- 305 Utils.Modules(Utils.ModuleAction.initModule); 306 307 Errors.PushAbortMethod(new Errors.AbortMethod(Abort)); 308 309 using (var src = new StringReader(gpdlString)) { 310 GPDefLex.src = src; 311 GPDefSyn.Parse(); 312 } 313 314 GPDefLex.InitLex(); 315 GPDefSyn.Interpret(); 316 MainFormManager.MainForm.ShowContent(GPDefSem.problem); 317 } 318 319 private void Abort(string abortKind, string moduleName, string methodName, string descr) { 320 321 61 var view = MainFormManager.CreateView(typeof(GpdlEditor)); 62 view.Show(); 322 63 } 323 64 } -
branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL.Views/3.4/HeuristicLab.Problems.GPDL.Views-3.4.csproj
r9430 r9519 173 173 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Problems.Instances.DataAnalysis-3.3.dll</HintPath> 174 174 </Reference> 175 <Reference Include="HeuristicLab.Problems.Instances.Views-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 176 <SpecificVersion>False</SpecificVersion> 177 <HintPath>..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Problems.Instances.Views-3.3.dll</HintPath> 178 </Reference> 175 179 <Reference Include="HeuristicLab.Random-3.3"> 176 180 <HintPath>c:\Program Files\HeuristicLab 3.3\HeuristicLab.Random-3.3.dll</HintPath> … … 196 200 </ItemGroup> 197 201 <ItemGroup> 202 <Compile Include="GpdlProblemInstanceConsumerView.cs"> 203 <SubType>UserControl</SubType> 204 </Compile> 205 <Compile Include="Properties\Resources.Designer.cs"> 206 <AutoGen>True</AutoGen> 207 <DesignTime>True</DesignTime> 208 <DependentUpon>Resources.resx</DependentUpon> 209 </Compile> 198 210 <None Include="HeuristicLab.snk" /> 211 <Compile Include="GpdlExampleDataDescriptor.cs" /> 199 212 <Compile Include="CreateProblemMenuItem.cs" /> 213 <Compile Include="GpdlEditor.cs"> 214 <SubType>UserControl</SubType> 215 </Compile> 216 <Compile Include="GpdlEditor.Designer.cs"> 217 <DependentUpon>GpdlEditor.cs</DependentUpon> 218 </Compile> 219 <Compile Include="GpdlExampleProvider.cs" /> 200 220 <Compile Include="Plugin.cs" /> 201 221 <Compile Include="Properties\AssemblyInfo.cs" /> … … 226 246 </ProjectReference> 227 247 </ItemGroup> 248 <ItemGroup> 249 <EmbeddedResource Include="GpdlEditor.resx"> 250 <DependentUpon>GpdlEditor.cs</DependentUpon> 251 </EmbeddedResource> 252 <EmbeddedResource Include="Properties\Resources.resx"> 253 <Generator>ResXFileCodeGenerator</Generator> 254 <LastGenOutput>Resources.Designer.cs</LastGenOutput> 255 </EmbeddedResource> 256 </ItemGroup> 257 <ItemGroup> 258 <None Include="Resources\Artificial Ant.txt" /> 259 </ItemGroup> 260 <ItemGroup> 261 <None Include="Resources\Factorial.txt" /> 262 </ItemGroup> 263 <ItemGroup> 264 <None Include="Resources\Fib.txt" /> 265 </ItemGroup> 266 <ItemGroup> 267 <None Include="Resources\multi-output-multiplier.txt" /> 268 </ItemGroup> 269 <ItemGroup> 270 <None Include="Resources\symbreg HEAL.txt" /> 271 </ItemGroup> 272 <ItemGroup> 273 <None Include="Resources\symbreg Koza.txt" /> 274 </ItemGroup> 228 275 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> 229 276 <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Note: See TracChangeset
for help on using the changeset viewer.