1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Linq;
|
---|
25 | using System.Text;
|
---|
26 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
27 | using HeuristicLab.Common;
|
---|
28 | using HeuristicLab.Core;
|
---|
29 | using HeuristicLab.Parameters;
|
---|
30 | using HeuristicLab.Data;
|
---|
31 | using HeuristicLab.Optimization;
|
---|
32 | using System.Threading;
|
---|
33 |
|
---|
34 | namespace HeuristicLab.SimulationCore.Samples {
|
---|
35 | [Item("SimpleSimulation", "A simple simulation.")]
|
---|
36 | [Creatable("Simulations")]
|
---|
37 | [StorableClass]
|
---|
38 | public sealed class SimpleSimulation: Simulation {
|
---|
39 | public override Type ProblemType {
|
---|
40 | get { return typeof(SimpleScenario); }
|
---|
41 | }
|
---|
42 |
|
---|
43 | private SimpleScenario Scenario {
|
---|
44 | get {
|
---|
45 | return Problem as SimpleScenario;
|
---|
46 | }
|
---|
47 | }
|
---|
48 |
|
---|
49 | public ValueParameter<IntValue> IterationsParameter {
|
---|
50 | get { return (ValueParameter<IntValue>)Parameters["Iterations"]; }
|
---|
51 | }
|
---|
52 |
|
---|
53 | public SimpleSimulation() : base() {
|
---|
54 | Parameters.Add(new ValueParameter<IntValue>("Iterations", "The number of iterations.", new IntValue(100)));
|
---|
55 | }
|
---|
56 | [StorableConstructor]
|
---|
57 | private SimpleSimulation(bool deserializing) : base(deserializing) { }
|
---|
58 | private SimpleSimulation(SimpleSimulation original, Cloner cloner)
|
---|
59 | : base(original, cloner) {
|
---|
60 | }
|
---|
61 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
62 | return new SimpleSimulation(this, cloner);
|
---|
63 | }
|
---|
64 |
|
---|
65 | protected override void Run(CancellationToken cancellationToken) {
|
---|
66 | IntValue counter = new IntValue(Scenario.InitialValueParameter.Value.Value);
|
---|
67 | Results.Add(new Result("Count", counter));
|
---|
68 |
|
---|
69 | int iterations = IterationsParameter.Value.Value;
|
---|
70 | for (int i = 0; i < iterations; i++) {
|
---|
71 | counter.Value++;
|
---|
72 | System.Threading.Thread.Sleep(250);
|
---|
73 | }
|
---|
74 | }
|
---|
75 | }
|
---|
76 | }
|
---|