Index: /trunk/sources/HeuristicLab.Optimizer/3.3/HeuristicLab.Optimizer-3.3.csproj
===================================================================
--- /trunk/sources/HeuristicLab.Optimizer/3.3/HeuristicLab.Optimizer-3.3.csproj (revision 11513)
+++ /trunk/sources/HeuristicLab.Optimizer/3.3/HeuristicLab.Optimizer-3.3.csproj (revision 11514)
@@ -135,8 +135,8 @@
-
-
-
-
+
+
+
+
Index: /trunk/sources/HeuristicLab.Optimizer/3.3/StartPage.cs
===================================================================
--- /trunk/sources/HeuristicLab.Optimizer/3.3/StartPage.cs (revision 11513)
+++ /trunk/sources/HeuristicLab.Optimizer/3.3/StartPage.cs (revision 11514)
@@ -145,6 +145,6 @@
groupLookup[dataAnalysisGroup] = dataAnalysisProblems;
var scripts = new List { "GA_QAP_Script", "GUI_Automation_Script", "OSGA_Rastrigin_Script",
- "GridSearch_RF_Classification", "GridSearch_RF_Regression",
- "GridSearch_SVM_Classification", "GridSearch_SVM_Regression" };
+ "GridSearch_RF_Classification_Script", "GridSearch_RF_Regression_Script",
+ "GridSearch_SVM_Classification_Script", "GridSearch_SVM_Regression_Script" };
groupLookup[scriptsGroup] = scripts;
}
Index: /trunk/sources/HeuristicLab.Scripting/3.3/CSharpScript.cs
===================================================================
--- /trunk/sources/HeuristicLab.Scripting/3.3/CSharpScript.cs (revision 11513)
+++ /trunk/sources/HeuristicLab.Scripting/3.3/CSharpScript.cs (revision 11514)
@@ -135,4 +135,5 @@
}
});
+ scriptThread.SetApartmentState(ApartmentState.STA);
scriptThread.Start();
}
Index: /trunk/sources/HeuristicLab.Tests/AssemblyInitializer.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/AssemblyInitializer.cs (revision 11514)
+++ /trunk/sources/HeuristicLab.Tests/AssemblyInitializer.cs (revision 11514)
@@ -0,0 +1,24 @@
+using System.IO;
+using System.Linq;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace HeuristicLab.Tests {
+ [TestClass]
+ public static class AssemblyInitializer {
+ private static string SamplesDirectory = SamplesUtils.SamplesDirectory;
+ private static string ScriptsDirectory = ScriptingUtils.ScriptsDirectory;
+
+ [AssemblyInitialize]
+ public static void AssemblyInitialize(TestContext testContext) {
+ // load all assemblies
+ PluginLoader.Assemblies.Any();
+
+ // create output directories for samples and scripts
+ if (!Directory.Exists(SamplesDirectory)) Directory.CreateDirectory(SamplesDirectory);
+ if (!Directory.Exists(ScriptsDirectory)) Directory.CreateDirectory(ScriptsDirectory);
+
+ // initialize the MainForm
+ ScriptingUtils.InitializeMainForm();
+ }
+ }
+}
Index: /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/CloningConstructorTest.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/CloningConstructorTest.cs (revision 11513)
+++ /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/CloningConstructorTest.cs (revision 11514)
@@ -21,5 +21,4 @@
using System;
-using System.Linq;
using System.Reflection;
using System.Text;
@@ -31,10 +30,4 @@
[TestClass]
public class CloningConstructorTest {
- // Use ClassInitialize to run code before running the first test in the class
- [ClassInitialize]
- public static void MyClassInitialize(TestContext testContext) {
- PluginLoader.Assemblies.Any();
- }
-
[TestMethod]
[TestCategory("General")]
Index: /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/ContentViewTests.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/ContentViewTests.cs (revision 11513)
+++ /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/ContentViewTests.cs (revision 11514)
@@ -31,14 +31,4 @@
[TestClass]
public class ContentViewTests {
- public ContentViewTests() {
- }
-
- // Use ClassInitialize to run code before running the first test in the class
- [ClassInitialize]
- public static void MyClassInitialize(TestContext testContext) {
- PluginLoader.Assemblies.Any();
- }
-
-
[TestMethod]
[TestCategory("General")]
Index: /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/DeepCloneableCloningTest.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/DeepCloneableCloningTest.cs (revision 11513)
+++ /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/DeepCloneableCloningTest.cs (revision 11514)
@@ -32,15 +32,6 @@
namespace HeuristicLab.Tests {
- ///
- /// Summary description for DeepCloneableCloningTest
- ///
[TestClass]
public class DeepCloneableCloningTest {
-
- [ClassInitialize]
- public static void MyClassInitialize(TestContext testContext) {
- PluginLoader.Assemblies.Any();
- }
-
private TestContext testContextInstance;
public TestContext TestContext {
Index: /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/InstantiateCreatablesTest.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/InstantiateCreatablesTest.cs (revision 11513)
+++ /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/InstantiateCreatablesTest.cs (revision 11514)
@@ -31,9 +31,4 @@
[TestClass]
public class InstantiateCreatablesTest {
- // Use ClassInitialize to run code before running the first test in the class
- [ClassInitialize]
- public static void MyClassInitialize(TestContext testContext) {
- PluginLoader.Assemblies.Any();
- }
[TestMethod]
[TestCategory("General")]
Index: /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/NamedItemTest.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/NamedItemTest.cs (revision 11513)
+++ /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/NamedItemTest.cs (revision 11514)
@@ -1,4 +1,3 @@
-using System.Linq;
-using System.Text;
+using System.Text;
using HeuristicLab.Common;
using HeuristicLab.Core;
@@ -9,9 +8,4 @@
[TestClass]
public class NamedItemTest {
- [ClassInitialize]
- public static void MyClassInitialize(TestContext testContext) {
- PluginLoader.Assemblies.Any();
- }
-
[TestMethod]
[TestCategory("General")]
Index: /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/ParameterVisibilityTest.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/ParameterVisibilityTest.cs (revision 11513)
+++ /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/ParameterVisibilityTest.cs (revision 11514)
@@ -31,10 +31,4 @@
[TestClass]
public class ParameterVisibilityTest {
- // Use ClassInitialize to run code before running the first test in the class
- [ClassInitialize]
- public static void MyClassInitialize(TestContext testContext) {
- PluginLoader.Assemblies.Any();
- }
-
private TestContext testContextInstance;
public TestContext TestContext {
Index: /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/EsGriewankSampleTest.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/EsGriewankSampleTest.cs (revision 11513)
+++ /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/EsGriewankSampleTest.cs (revision 11514)
@@ -29,16 +29,7 @@
namespace HeuristicLab.Tests {
- ///
- /// Summary description for EsGriewankSampleTest
- ///
[TestClass]
public class EsGriewankSampleTest {
- private const string samplesDirectory = SamplesUtils.Directory;
-
- [ClassInitialize]
- public static void MyClassInitialize(TestContext testContext) {
- if (!Directory.Exists(samplesDirectory))
- Directory.CreateDirectory(samplesDirectory);
- }
+ private const string SampleFileName = "ES_Griewank";
[TestMethod]
@@ -47,5 +38,6 @@
public void CreateEsGriewankSampleTest() {
var es = CreateEsGriewankSample();
- XmlGenerator.Serialize(es, @"Samples\ES_Griewank.hl");
+ string path = Path.Combine(SamplesUtils.SamplesDirectory, SampleFileName + SamplesUtils.SampleFileExtension);
+ XmlGenerator.Serialize(es, path);
}
Index: /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GATspSampleTest.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GATspSampleTest.cs (revision 11513)
+++ /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GATspSampleTest.cs (revision 11514)
@@ -33,11 +33,5 @@
[TestClass]
public class GATspSampleTest {
- private const string samplesDirectory = SamplesUtils.Directory;
- [ClassInitialize]
- public static void MyClassInitialize(TestContext testContext) {
- if (!Directory.Exists(samplesDirectory))
- Directory.CreateDirectory(samplesDirectory);
- }
-
+ private const string SampleFileName = "GA_TSP";
[TestMethod]
@@ -46,6 +40,8 @@
public void CreateGaTspSampleTest() {
var ga = CreateGaTspSample();
- XmlGenerator.Serialize(ga, @"Samples\GA_TSP.hl");
+ string path = Path.Combine(SamplesUtils.SamplesDirectory, SampleFileName + SamplesUtils.SampleFileExtension);
+ XmlGenerator.Serialize(ga, path);
}
+
[TestMethod]
[TestCategory("Samples.Execute")]
@@ -63,4 +59,5 @@
private GeneticAlgorithm CreateGaTspSample() {
GeneticAlgorithm ga = new GeneticAlgorithm();
+
#region Problem Configuration
var provider = new TSPLIBTSPInstanceProvider();
@@ -77,4 +74,5 @@
ga, 100, 1, 1000, 0.05);
#endregion
+
return ga;
}
Index: /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GAVrpSampleTest.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GAVrpSampleTest.cs (revision 11513)
+++ /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GAVrpSampleTest.cs (revision 11514)
@@ -34,16 +34,7 @@
namespace HeuristicLab.Tests {
- ///
- /// Summary description for GAVrpSampleTest
- ///
[TestClass]
public class GAVrpSampleTest {
- private const string samplesDirectory = SamplesUtils.Directory;
- [ClassInitialize]
- public static void MyClassInitialize(TestContext testContext) {
- if (!Directory.Exists(samplesDirectory))
- Directory.CreateDirectory(samplesDirectory);
- }
-
+ private const string SampleFileName = "GA_VRP";
[TestMethod]
@@ -52,5 +43,6 @@
public void CreateGaVrpSampleTest() {
var ga = CreateGaVrpSample();
- XmlGenerator.Serialize(ga, @"Samples\GA_VRP.hl");
+ string path = Path.Combine(SamplesUtils.SamplesDirectory, SampleFileName + SamplesUtils.SampleFileExtension);
+ XmlGenerator.Serialize(ga, path);
}
@@ -70,4 +62,5 @@
private GeneticAlgorithm CreateGaVrpSample() {
GeneticAlgorithm ga = new GeneticAlgorithm();
+
#region Problem Configuration
VehicleRoutingProblem vrpProblem = new VehicleRoutingProblem();
@@ -117,4 +110,5 @@
.Single(), true);
#endregion
+
return ga;
}
Index: /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GPArtificialAntSampleTest.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GPArtificialAntSampleTest.cs (revision 11513)
+++ /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GPArtificialAntSampleTest.cs (revision 11514)
@@ -30,15 +30,7 @@
namespace HeuristicLab.Tests {
- ///
- /// Summary description for GPArtificialAntSampleTest
- ///
[TestClass]
public class GPArtificialAntSampleTest {
- private const string samplesDirectory = SamplesUtils.Directory;
- [ClassInitialize]
- public static void MyClassInitialize(TestContext testContext) {
- if (!Directory.Exists(samplesDirectory))
- Directory.CreateDirectory(samplesDirectory);
- }
+ private const string SampleFileName = "SGP_SantaFe";
[TestMethod]
@@ -47,5 +39,6 @@
public void CreateGpArtificialAntSampleTest() {
var ga = CreateGpArtificialAntSample();
- XmlGenerator.Serialize(ga, @"Samples\SGP_SantaFe.hl");
+ string path = Path.Combine(SamplesUtils.SamplesDirectory, SampleFileName + SamplesUtils.SampleFileExtension);
+ XmlGenerator.Serialize(ga, path);
}
@@ -65,4 +58,5 @@
public GeneticAlgorithm CreateGpArtificialAntSample() {
GeneticAlgorithm ga = new GeneticAlgorithm();
+
#region Problem Configuration
ArtificialAntProblem antProblem = new ArtificialAntProblem();
@@ -94,4 +88,5 @@
.Single(), false);
#endregion
+
return ga;
}
Index: /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GPLawnMowerSampleTest.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GPLawnMowerSampleTest.cs (revision 11513)
+++ /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GPLawnMowerSampleTest.cs (revision 11514)
@@ -20,5 +20,4 @@
#endregion
-using System.IO;
using System.Linq;
using HeuristicLab.Algorithms.GeneticAlgorithm;
@@ -28,16 +27,6 @@
namespace HeuristicLab.Tests {
- ///
- /// Summary description for GPLawnMowerSampleTest
- ///
[TestClass]
public class GPLawnMowerSampleTest {
- private const string samplesDirectory = SamplesUtils.Directory;
- [ClassInitialize]
- public static void MyClassInitialize(TestContext testContext) {
- if (!Directory.Exists(samplesDirectory))
- Directory.CreateDirectory(samplesDirectory);
- }
-
[TestMethod]
[TestCategory("Samples.Execute")]
@@ -57,5 +46,4 @@
#endregion
-
#region Algorithm Configuration
Index: /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GPMultiplexerSampleTest.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GPMultiplexerSampleTest.cs (revision 11513)
+++ /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GPMultiplexerSampleTest.cs (revision 11514)
@@ -33,10 +33,5 @@
[TestClass]
public class GPMultiplexerSampleTest {
- private const string samplesDirectory = SamplesUtils.Directory;
- [ClassInitialize]
- public static void MyClassInitialize(TestContext testContext) {
- if (!Directory.Exists(samplesDirectory))
- Directory.CreateDirectory(samplesDirectory);
- }
+ private const string SampleFileName = "GP_Multiplexer";
[TestMethod]
@@ -45,5 +40,5 @@
public void CreateGpMultiplexerSampleTest() {
var ga = CreateGpMultiplexerSample();
- var path = Path.Combine(samplesDirectory, "GP_Multiplexer.hl");
+ string path = Path.Combine(SamplesUtils.SamplesDirectory, SampleFileName + SamplesUtils.SampleFileExtension);
XmlGenerator.Serialize(ga, path);
}
Index: /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GPSymbolicClassificationSampleTest.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GPSymbolicClassificationSampleTest.cs (revision 11513)
+++ /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GPSymbolicClassificationSampleTest.cs (revision 11514)
@@ -33,15 +33,7 @@
namespace HeuristicLab.Tests {
- ///
- /// Summary description for GPSymbolicClassificationSampleTest
- ///
[TestClass]
public class GPSymbolicClassificationSampleTest {
- private const string samplesDirectory = SamplesUtils.Directory;
- [ClassInitialize]
- public static void MyClassInitialize(TestContext testContext) {
- if (!Directory.Exists(samplesDirectory))
- Directory.CreateDirectory(samplesDirectory);
- }
+ private const string SampleFileName = "SGP_SymbClass";
[TestMethod]
@@ -50,5 +42,6 @@
public void CreateGpSymbolicClassificationSampleTest() {
var ga = CreateGpSymbolicClassificationSample();
- XmlGenerator.Serialize(ga, @"Samples\SGP_SymbClass.hl");
+ string path = Path.Combine(SamplesUtils.SamplesDirectory, SampleFileName + SamplesUtils.SampleFileExtension);
+ XmlGenerator.Serialize(ga, path);
}
Index: /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GPSymbolicRegressionSampleTest.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GPSymbolicRegressionSampleTest.cs (revision 11513)
+++ /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GPSymbolicRegressionSampleTest.cs (revision 11514)
@@ -33,16 +33,7 @@
namespace HeuristicLab.Tests {
- ///
- /// Summary description for GPSymbolicRegressionSampleTest
- ///
[TestClass]
public class GPSymbolicRegressionSampleTest {
- private const string samplesDirectory = SamplesUtils.Directory;
- [ClassInitialize]
- public static void MyClassInitialize(TestContext testContext) {
- if (!Directory.Exists(samplesDirectory))
- Directory.CreateDirectory(samplesDirectory);
- }
-
+ private const string SampleFileName = "SGP_SymbReg";
[TestMethod]
@@ -51,5 +42,6 @@
public void CreateGpSymbolicRegressionSampleTest() {
var ga = CreateGpSymbolicRegressionSample();
- XmlGenerator.Serialize(ga, @"Samples\SGP_SymbReg.hl");
+ string path = Path.Combine(SamplesUtils.SamplesDirectory, SampleFileName + SamplesUtils.SampleFileExtension);
+ XmlGenerator.Serialize(ga, path);
}
[TestMethod]
Index: /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GPTimeSeriesSampleTest.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GPTimeSeriesSampleTest.cs (revision 11513)
+++ /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GPTimeSeriesSampleTest.cs (revision 11514)
@@ -32,10 +32,5 @@
[TestClass]
public class GPTimeSeriesSampleTest {
- private const string samplesDirectory = SamplesUtils.Directory;
- [ClassInitialize]
- public static void MyClassInitialize(TestContext testContext) {
- if (!Directory.Exists(samplesDirectory))
- Directory.CreateDirectory(samplesDirectory);
- }
+ private const string SampleFileName = "OSGP_TimeSeries";
[TestMethod]
@@ -44,5 +39,5 @@
public void CreateGpTimeSeriesSampleTest() {
var ga = CreateGpTimeSeriesSample();
- var path = Path.Combine(samplesDirectory, "OSGP_TimeSeries.hl");
+ string path = Path.Combine(SamplesUtils.SamplesDirectory, SampleFileName + SamplesUtils.SampleFileExtension);
XmlGenerator.Serialize(ga, path);
}
Index: /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GaussianProcessRegressionSampleTest.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GaussianProcessRegressionSampleTest.cs (revision 11513)
+++ /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GaussianProcessRegressionSampleTest.cs (revision 11514)
@@ -29,15 +29,7 @@
namespace HeuristicLab.Tests {
- ///
- /// Summary description for GaussianProcessRegressionSampleTest
- ///
[TestClass]
public class GaussianProcessRegressionSampleTest {
- private const string samplesDirectory = SamplesUtils.Directory;
- [ClassInitialize]
- public static void MyClassInitialize(TestContext testContext) {
- if (!Directory.Exists(samplesDirectory))
- Directory.CreateDirectory(samplesDirectory);
- }
+ private const string SampleFileName = "GPR";
[TestMethod]
@@ -46,6 +38,8 @@
public void CreateGaussianProcessRegressionSampleTest() {
var gpr = CreateGaussianProcessRegressionSample();
- XmlGenerator.Serialize(gpr, @"Samples\GPR.hl");
+ string path = Path.Combine(SamplesUtils.SamplesDirectory, SampleFileName + SamplesUtils.SampleFileExtension);
+ XmlGenerator.Serialize(gpr, path);
}
+
[TestMethod]
[TestCategory("Samples.Execute")]
@@ -66,4 +60,5 @@
var regProblem = new RegressionProblem();
regProblem.Load(provider.LoadData(instance));
+
#region Algorithm Configuration
gpr.Name = "Gaussian Process Regression";
@@ -77,4 +72,5 @@
gpr.SetSeedRandomly = true;
#endregion
+
gpr.Engine = new ParallelEngine.ParallelEngine();
return gpr;
Index: /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GeSymbolicRegressionSampleTest.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GeSymbolicRegressionSampleTest.cs (revision 11513)
+++ /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GeSymbolicRegressionSampleTest.cs (revision 11514)
@@ -30,17 +30,9 @@
namespace HeuristicLab.Tests {
- ///
- /// Summary description for GeSymbolicRegressionSampleTest
- ///
[TestClass]
public class GeSymbolicRegressionSampleTest {
- private const string samplesDirectory = SamplesUtils.Directory;
- [ClassInitialize]
- public static void MyClassInitialize(TestContext testContext) {
- if (!Directory.Exists(samplesDirectory))
- Directory.CreateDirectory(samplesDirectory);
- }
+ #region artificial ant
+ private const string GeArtificialAntSampleFileName = "GE_ArtificialAnt";
- #region artificial ant
[TestMethod]
[TestCategory("Samples.Create")]
@@ -48,5 +40,6 @@
public void CreateGeArtificialAntSampleTest() {
var geaa = CreateGeArtificialAntSample();
- XmlGenerator.Serialize(geaa, @"Samples\GE_ArtificialAnt.hl");
+ string path = Path.Combine(SamplesUtils.SamplesDirectory, GeArtificialAntSampleFileName + SamplesUtils.SampleFileExtension);
+ XmlGenerator.Serialize(geaa, path);
}
@@ -62,4 +55,5 @@
public OffspringSelectionGeneticAlgorithm CreateGeArtificialAntSample() {
OffspringSelectionGeneticAlgorithm ga = new OffspringSelectionGeneticAlgorithm();
+
#region Problem Configuration
var problem = new HeuristicLab.Problems.GrammaticalEvolution.GEArtificialAntProblem();
@@ -72,4 +66,5 @@
ga, 200, 1, 50, 0.05, 200);
#endregion
+
return ga;
}
@@ -77,5 +72,6 @@
#region symbolic regression
- #endregion
+ private const string GeSymbolicRegressionSampleFileName = "GE_SymbReg";
+
[TestMethod]
[TestCategory("Samples.Create")]
@@ -83,5 +79,6 @@
public void CreateGeSymbolicRegressionSampleTest() {
var geSymbReg = CreateGeSymbolicRegressionSample();
- XmlGenerator.Serialize(geSymbReg, @"Samples\GE_SymbReg.hl");
+ string path = Path.Combine(SamplesUtils.SamplesDirectory, GeSymbolicRegressionSampleFileName + SamplesUtils.SampleFileExtension);
+ XmlGenerator.Serialize(geSymbReg, path);
}
@@ -97,4 +94,5 @@
public OffspringSelectionGeneticAlgorithm CreateGeSymbolicRegressionSample() {
var ga = new OffspringSelectionGeneticAlgorithm();
+
#region Problem Configuration
var problem = new HeuristicLab.Problems.GrammaticalEvolution.GESymbolicRegressionSingleObjectiveProblem();
@@ -116,6 +114,8 @@
ga, 1000, 1, 50, 0.05, 200);
#endregion
+
return ga;
}
+ #endregion
}
}
Index: /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/IslandGaTspSampleTest.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/IslandGaTspSampleTest.cs (revision 11513)
+++ /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/IslandGaTspSampleTest.cs (revision 11514)
@@ -34,10 +34,5 @@
[TestClass]
public class UnitTest1 {
- private const string samplesDirectory = SamplesUtils.Directory;
- [ClassInitialize]
- public static void MyClassInitialize(TestContext testContext) {
- if (!Directory.Exists(samplesDirectory))
- Directory.CreateDirectory(samplesDirectory);
- }
+ private const string SampleFileName = "IslandGA_TSP";
[TestMethod]
@@ -46,5 +41,6 @@
public void CreateIslandGaTspSampleTest() {
var ga = CreateIslandGaTspSample();
- XmlGenerator.Serialize(ga, @"Samples\IslandGA_TSP.hl");
+ string path = Path.Combine(SamplesUtils.SamplesDirectory, SampleFileName + SamplesUtils.SampleFileExtension);
+ XmlGenerator.Serialize(ga, path);
}
[TestMethod]
Index: /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/LocalSearchKnapsackSampleTest.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/LocalSearchKnapsackSampleTest.cs (revision 11513)
+++ /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/LocalSearchKnapsackSampleTest.cs (revision 11514)
@@ -30,15 +30,7 @@
namespace HeuristicLab.Tests {
- ///
- /// Summary description for LocalSearchKnapsackSampleTest
- ///
[TestClass]
public class LocalSearchKnapsackSampleTest {
- private const string samplesDirectory = SamplesUtils.Directory;
- [ClassInitialize]
- public static void MyClassInitialize(TestContext testContext) {
- if (!Directory.Exists(samplesDirectory))
- Directory.CreateDirectory(samplesDirectory);
- }
+ private const string SampleFileName = "LS_Knapsack";
[TestMethod]
@@ -47,5 +39,6 @@
public void CreateLocalSearchKnapsackSampleTest() {
var ls = CreateLocalSearchKnapsackSample();
- XmlGenerator.Serialize(ls, @"Samples\LS_Knapsack.hl");
+ string path = Path.Combine(SamplesUtils.SamplesDirectory, SampleFileName + SamplesUtils.SampleFileExtension);
+ XmlGenerator.Serialize(ls, path);
}
[TestMethod]
Index: /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/PsoSchwefelSampleTest.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/PsoSchwefelSampleTest.cs (revision 11513)
+++ /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/PsoSchwefelSampleTest.cs (revision 11514)
@@ -32,15 +32,7 @@
namespace HeuristicLab.Tests {
- ///
- /// Summary description for PsoSchwefelSampleTest
- ///
[TestClass]
public class PsoSchwefelSampleTest {
- private const string samplesDirectory = SamplesUtils.Directory;
- [ClassInitialize]
- public static void MyClassInitialize(TestContext testContext) {
- if (!Directory.Exists(samplesDirectory))
- Directory.CreateDirectory(samplesDirectory);
- }
+ private const string SampleFileName = "PSO_Schwefel";
[TestMethod]
@@ -49,5 +41,6 @@
public void CreatePsoSchwefelSampleTest() {
var pso = CreatePsoSchwefelSample();
- XmlGenerator.Serialize(pso, @"Samples\PSO_Schwefel.hl");
+ string path = Path.Combine(SamplesUtils.SamplesDirectory, SampleFileName + SamplesUtils.SampleFileExtension);
+ XmlGenerator.Serialize(pso, path);
}
[TestMethod]
Index: /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/RAPGASchedulingSampleTest.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/RAPGASchedulingSampleTest.cs (revision 11513)
+++ /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/RAPGASchedulingSampleTest.cs (revision 11514)
@@ -29,15 +29,7 @@
namespace HeuristicLab.Tests {
- ///
- /// Summary description for RAPGASchedulingSampleTest
- ///
[TestClass]
public class RAPGASchedulingSampleTest {
- private const string samplesDirectory = SamplesUtils.Directory;
- [ClassInitialize]
- public static void MyClassInitialize(TestContext testContext) {
- if (!Directory.Exists(samplesDirectory))
- Directory.CreateDirectory(samplesDirectory);
- }
+ private const string SampleFileName = "RAPGA_JSSP";
[TestMethod]
@@ -46,5 +38,6 @@
public void CreateRAPGASchedulingSampleTest() {
var ss = CreateRAPGASchedulingSample();
- XmlGenerator.Serialize(ss, @"Samples\RAPGA_JSSP.hl");
+ string path = Path.Combine(SamplesUtils.SamplesDirectory, SampleFileName + SamplesUtils.SampleFileExtension);
+ XmlGenerator.Serialize(ss, path);
}
Index: /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/SamplesUtils.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/SamplesUtils.cs (revision 11513)
+++ /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/SamplesUtils.cs (revision 11514)
@@ -12,5 +12,6 @@
namespace HeuristicLab.Tests {
public static class SamplesUtils {
- public const string Directory = @"Samples\";
+ public const string SamplesDirectory = @"Samples\";
+ public const string SampleFileExtension = ".hl";
public static void RunAlgorithm(IAlgorithm a) {
Index: /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/ScatterSearchVRPSampleTest.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/ScatterSearchVRPSampleTest.cs (revision 11513)
+++ /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/ScatterSearchVRPSampleTest.cs (revision 11514)
@@ -29,15 +29,7 @@
namespace HeuristicLab.Tests {
- ///
- /// Summary description for ScatterSearchVRPSampleTest
- ///
[TestClass]
public class ScatterSearchVRPSampleTest {
- private const string samplesDirectory = SamplesUtils.Directory;
- [ClassInitialize]
- public static void MyClassInitialize(TestContext testContext) {
- if (!Directory.Exists(samplesDirectory))
- Directory.CreateDirectory(samplesDirectory);
- }
+ private const string SampleFileName = "SS_VRP";
[TestMethod]
@@ -46,5 +38,6 @@
public void CreateScatterSearchVRPSampleTest() {
var ss = CreateScatterSearchVRPSample();
- XmlGenerator.Serialize(ss, @"Samples\SS_VRP.hl");
+ string path = Path.Combine(SamplesUtils.SamplesDirectory, SampleFileName + SamplesUtils.SampleFileExtension);
+ XmlGenerator.Serialize(ss, path);
}
Index: /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/SimulatedAnnealingRastriginSampleTest.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/SimulatedAnnealingRastriginSampleTest.cs (revision 11513)
+++ /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/SimulatedAnnealingRastriginSampleTest.cs (revision 11514)
@@ -31,15 +31,7 @@
namespace HeuristicLab.Tests {
- ///
- /// Summary description for SimulatedAnnealingRastriginSampleTest
- ///
[TestClass]
public class SimulatedAnnealingRastriginSampleTest {
- private const string samplesDirectory = SamplesUtils.Directory;
- [ClassInitialize]
- public static void MyClassInitialize(TestContext testContext) {
- if (!Directory.Exists(samplesDirectory))
- Directory.CreateDirectory(samplesDirectory);
- }
+ private const string SampleFileName = "SA_Rastrigin";
[TestMethod]
@@ -48,5 +40,6 @@
public void CreateSimulatedAnnealingRastriginSampleTest() {
var sa = CreateSimulatedAnnealingRastriginSample();
- XmlGenerator.Serialize(sa, @"Samples\SA_Rastrigin.hl");
+ string path = Path.Combine(SamplesUtils.SamplesDirectory, SampleFileName + SamplesUtils.SampleFileExtension);
+ XmlGenerator.Serialize(sa, path);
}
[TestMethod]
Index: /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/TabuSearchTspSampleTest.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/TabuSearchTspSampleTest.cs (revision 11513)
+++ /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/TabuSearchTspSampleTest.cs (revision 11514)
@@ -30,16 +30,7 @@
namespace HeuristicLab.Tests {
- ///
- /// Summary description for TabuSearchTspSampleTest
- ///
[TestClass]
public class TabuSearchTspSampleTest {
- private const string samplesDirectory = SamplesUtils.Directory;
- [ClassInitialize]
- public static void MyClassInitialize(TestContext testContext) {
- if (!Directory.Exists(samplesDirectory))
- Directory.CreateDirectory(samplesDirectory);
- }
-
+ private const string SampleFileName = "TS_TSP";
[TestMethod]
@@ -48,5 +39,6 @@
public void CreateTabuSearchTspSampleTest() {
var ts = CreateTabuSearchTspSample();
- XmlGenerator.Serialize(ts, @"Samples\TS_TSP.hl");
+ string path = Path.Combine(SamplesUtils.SamplesDirectory, SampleFileName + SamplesUtils.SampleFileExtension);
+ XmlGenerator.Serialize(ts, path);
}
[TestMethod]
Index: /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/TabuSearchVRPSampleTest.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/TabuSearchVRPSampleTest.cs (revision 11513)
+++ /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/TabuSearchVRPSampleTest.cs (revision 11514)
@@ -30,15 +30,7 @@
namespace HeuristicLab.Tests {
- ///
- /// Summary description for TabuSearchVRPSampleTest
- ///
[TestClass]
public class TabuSearchVRPSampleTest {
- private const string samplesDirectory = SamplesUtils.Directory;
- [ClassInitialize]
- public static void MyClassInitialize(TestContext testContext) {
- if (!Directory.Exists(samplesDirectory))
- Directory.CreateDirectory(samplesDirectory);
- }
+ private const string SampleFileName = "TS_VRP";
[TestMethod]
@@ -47,5 +39,6 @@
public void CreateTabuSearchVRPSampleTest() {
var vrp = CreateTabuSearchVrpSample();
- XmlGenerator.Serialize(vrp, @"Samples\TS_VRP.hl");
+ string path = Path.Combine(SamplesUtils.SamplesDirectory, SampleFileName + SamplesUtils.SampleFileExtension);
+ XmlGenerator.Serialize(vrp, path);
}
[TestMethod]
Index: /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/VnsTspSampleTest.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/VnsTspSampleTest.cs (revision 11513)
+++ /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/VnsTspSampleTest.cs (revision 11514)
@@ -31,15 +31,7 @@
namespace HeuristicLab.Tests {
- ///
- /// Summary description for VnsTspSampleTest
- ///
[TestClass]
public class VnsTspSampleTest {
- private const string samplesDirectory = SamplesUtils.Directory;
- [ClassInitialize]
- public static void MyClassInitialize(TestContext testContext) {
- if (!Directory.Exists(samplesDirectory))
- Directory.CreateDirectory(samplesDirectory);
- }
+ private const string SampleFileName = "VNS_TSP";
[TestMethod]
@@ -48,5 +40,6 @@
public void CreateVnsTspSampleTest() {
var vns = CreateVnsTspSample();
- XmlGenerator.Serialize(vns, @"Samples\VNS_TSP.hl");
+ string path = Path.Combine(SamplesUtils.SamplesDirectory, SampleFileName + SamplesUtils.SampleFileExtension);
+ XmlGenerator.Serialize(vns, path);
}
[TestMethod]
Index: /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/StorableConstructorTest.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/StorableConstructorTest.cs (revision 11513)
+++ /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/StorableConstructorTest.cs (revision 11514)
@@ -33,11 +33,4 @@
[TestClass]
public class StorableConstructorTest {
-
- // Use ClassInitialize to run code before running the first test in the class
- [ClassInitialize]
- public static void MyClassInitialize(TestContext testContext) {
- PluginLoader.Assemblies.Any();
- }
-
[TestMethod]
[TestCategory("General")]
Index: /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/ToStringTest.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/ToStringTest.cs (revision 11513)
+++ /trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/ToStringTest.cs (revision 11514)
@@ -21,5 +21,4 @@
using System;
-using System.Linq;
using HeuristicLab.Core;
using HeuristicLab.PluginInfrastructure;
@@ -29,15 +28,8 @@
[TestClass]
public class ToStringTest {
-
private TestContext testContextInstance;
public TestContext TestContext {
get { return testContextInstance; }
set { testContextInstance = value; }
- }
-
- // Use ClassInitialize to run code before running the first test in the class
- [ClassInitialize]
- public static void MyClassInitialize(TestContext testContext) {
- PluginLoader.Assemblies.Any();
}
Index: /trunk/sources/HeuristicLab.Tests/HeuristicLab.PluginInfraStructure-3.3/TypeExtensionsTest.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/HeuristicLab.PluginInfraStructure-3.3/TypeExtensionsTest.cs (revision 11513)
+++ /trunk/sources/HeuristicLab.Tests/HeuristicLab.PluginInfraStructure-3.3/TypeExtensionsTest.cs (revision 11514)
@@ -29,7 +29,4 @@
namespace HeuristicLab.PluginInfrastructure.Tests {
- ///
- /// Summary description for TypeDiscoveryTest
- ///
[TestClass]
public class TypeExtensionsTest {
Index: /trunk/sources/HeuristicLab.Tests/HeuristicLab.Problems.VehicleRouting-3.4/VRPInstancesTest.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/HeuristicLab.Problems.VehicleRouting-3.4/VRPInstancesTest.cs (revision 11513)
+++ /trunk/sources/HeuristicLab.Tests/HeuristicLab.Problems.VehicleRouting-3.4/VRPInstancesTest.cs (revision 11514)
@@ -25,5 +25,4 @@
using System.Text;
using HeuristicLab.Problems.Instances;
-using HeuristicLab.Tests;
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -31,9 +30,4 @@
[TestClass]
public class VRPInstancesTest {
- [ClassInitialize]
- public static void MyClassInitialize(TestContext testContext) {
- PluginLoader.Assemblies.Any();
- }
-
[TestMethod]
[TestCategory("Problems.VehicleRouting")]
Index: unk/sources/HeuristicLab.Tests/HeuristicLab.Scripting-3.3/GridSearchScriptTest.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/HeuristicLab.Scripting-3.3/GridSearchScriptTest.cs (revision 11513)
+++ (revision )
@@ -1,207 +1,0 @@
-#region License Information
-/* HeuristicLab
- * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
- *
- * This file is part of HeuristicLab.
- *
- * HeuristicLab is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * HeuristicLab is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with HeuristicLab. If not, see .
- */
-#endregion
-
-using System;
-using System.CodeDom.Compiler;
-using System.IO;
-using System.Linq;
-using System.Reflection;
-using System.Threading;
-using HeuristicLab.Common;
-using HeuristicLab.Core;
-using HeuristicLab.Optimizer;
-using HeuristicLab.Persistence.Default.Xml;
-using HeuristicLab.Problems.DataAnalysis;
-using HeuristicLab.Scripting;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-namespace HeuristicLab.Tests {
- [TestClass]
- public class GridSearchScriptTest {
- private const string PathPrefix = "HeuristicLab.Optimizer.Documents.";
- private const string PathSuffix = ".hl";
- private const string SvmClassificationScriptName = "GridSearch_SVM_Classification";
- private const string SvmRegressionScriptName = "GridSearch_SVM_Regression";
- private const string RandomForestRegressionScriptName = "GridSearch_RF_Regression";
- private const string RandomForestClassificationScriptName = "GridSearch_RF_Classification";
- private const string SamplesDirectory = SamplesUtils.Directory;
-
- private readonly ManualResetEvent manualResetEvent = new ManualResetEvent(false);
-
- [ClassInitialize]
- public static void MyClassInitialize(TestContext testContext) {
- PluginLoader.Assemblies.Any();
- if (!Directory.Exists(SamplesDirectory))
- Directory.CreateDirectory(SamplesDirectory);
- }
-
- [TestMethod]
- [TestCategory("Scripting")]
- public void RunRandomForestRegressionScriptTest() {
- var assembly = new StartPage().GetType().Assembly;
- const string name = PathPrefix + RandomForestRegressionScriptName + PathSuffix;
- var script = (CSharpScript)LoadSample(name, assembly);
-
- try {
- script.Compile();
- }
- catch {
- if (script.CompileErrors.HasErrors) {
- ShowCompilationResults(script);
- throw new Exception("Compilation failed.");
- } else {
- Console.WriteLine("Compilation succeeded.");
- }
- }
- finally {
- script.ScriptExecutionFinished += script_ExecutionFinished;
- script.Execute();
- var vs = script.VariableStore;
- var solution = (IRegressionSolution)vs["demo_bestSolution"];
- Assert.IsTrue(solution.TrainingRSquared.IsAlmost(1));
- }
- }
-
- [TestMethod]
- [TestCategory("Scripting")]
- public void RunRandomForestClassificationScriptTest() {
- var assembly = new StartPage().GetType().Assembly;
- const string name = PathPrefix + RandomForestClassificationScriptName + PathSuffix;
- var script = (CSharpScript)LoadSample(name, assembly);
-
- try {
- script.Compile();
- }
- catch {
- if (script.CompileErrors.HasErrors) {
- ShowCompilationResults(script);
- throw new Exception("Compilation failed.");
- } else {
- Console.WriteLine("Compilation succeeded.");
- }
- }
- finally {
- script.ScriptExecutionFinished += script_ExecutionFinished;
- script.Execute();
- var vs = script.VariableStore;
- var solution = (IClassificationSolution)vs["demo_bestSolution"];
- Assert.IsTrue(solution.TrainingAccuracy.IsAlmost(1) && solution.TestAccuracy.IsAlmost(0.953125));
- }
- }
-
- [TestMethod]
- [TestCategory("Scripting")]
- public void RunSvmRegressionScriptTest() {
- var assembly = new StartPage().GetType().Assembly;
- const string name = PathPrefix + SvmRegressionScriptName + PathSuffix;
- var script = (CSharpScript)LoadSample(name, assembly);
-
- try {
- script.Compile();
- }
- catch {
- if (script.CompileErrors.HasErrors) {
- ShowCompilationResults(script);
- throw new Exception("Compilation failed.");
- } else {
- Console.WriteLine("Compilation succeeded.");
- }
- }
- finally {
- script.ScriptExecutionFinished += script_ExecutionFinished;
- script.Execute();
- var vs = script.VariableStore;
- var solution = (IRegressionSolution)vs["demo_bestSolution"];
- Assert.IsTrue(solution.TrainingRSquared.IsAlmost(0.066221959224331) && solution.TestRSquared.IsAlmost(0.0794407638195883));
- }
- }
-
- [TestMethod]
- [TestCategory("Scripting")]
- public void RunSvmClassificationScriptTest() {
- var assembly = new StartPage().GetType().Assembly;
- const string name = PathPrefix + SvmClassificationScriptName + PathSuffix;
- var script = (CSharpScript)LoadSample(name, assembly);
-
- try {
- script.Compile();
- }
- catch {
- if (script.CompileErrors.HasErrors) {
- ShowCompilationResults(script);
- throw new Exception("Compilation failed.");
- } else {
- Console.WriteLine("Compilation succeeded.");
- }
- }
- finally {
- script.ScriptExecutionFinished += script_ExecutionFinished;
- script.Execute();
- manualResetEvent.WaitOne();
- var vs = script.VariableStore;
- var solution = (IClassificationSolution)vs["demo_bestSolution"];
- Assert.IsTrue(solution.TrainingAccuracy.IsAlmost(0.817472698907956) && solution.TestAccuracy.IsAlmost(0.809375));
- }
- }
-
- #region Helpers
- private static void ShowCompilationResults(Script script) {
- if (script.CompileErrors.Count == 0) return;
- var msgs = script.CompileErrors.OfType()
- .OrderBy(x => x.IsWarning)
- .ThenBy(x => x.Line)
- .ThenBy(x => x.Column);
- foreach (var m in msgs) {
- Console.WriteLine(m);
- }
- }
-
- private INamedItem LoadSample(string name, Assembly assembly) {
- string path = Path.GetTempFileName();
- INamedItem item = null;
- try {
- using (var stream = assembly.GetManifestResourceStream(name)) {
- WriteStreamToTempFile(stream, path); // create a file in a temporary folder (persistence cannot load these files directly from the stream)
- item = XmlParser.Deserialize(path);
- }
- }
- catch (Exception) {
- }
- finally {
- if (File.Exists(path)) {
- File.Delete(path); // make sure we remove the temporary file
- }
- }
- return item;
- }
-
- private void WriteStreamToTempFile(Stream stream, string path) {
- using (FileStream output = new FileStream(path, FileMode.Create, FileAccess.Write)) {
- stream.CopyTo(output);
- }
- }
-
- private void script_ExecutionFinished(object sender, EventArgs a) {
- manualResetEvent.Set();
- }
- #endregion
- }
-}
Index: /trunk/sources/HeuristicLab.Tests/HeuristicLab.Scripting-3.3/ScriptingUtils.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/HeuristicLab.Scripting-3.3/ScriptingUtils.cs (revision 11514)
+++ /trunk/sources/HeuristicLab.Tests/HeuristicLab.Scripting-3.3/ScriptingUtils.cs (revision 11514)
@@ -0,0 +1,63 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using System;
+using System.IO;
+using System.Threading;
+using HeuristicLab.MainForm;
+using HeuristicLab.MainForm.WindowsForms;
+using HeuristicLab.Scripting;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace HeuristicLab.Tests {
+ public static class ScriptingUtils {
+ public const string ScriptsDirectory = @"Scripts\";
+ public const string ScriptSourcesDirectory = @"Test Resources\Script Sources\";
+ public const string ScriptFileExtension = ".hl";
+ public const string ScriptSourceFileExtension = ".cs";
+
+ public static void RunScript(CSharpScript s) {
+ var trigger = new EventWaitHandle(false, EventResetMode.ManualReset);
+ Exception ex = null;
+
+ s.ScriptExecutionFinished += (sender, e) => { ex = e.Value; trigger.Set(); };
+ s.Execute();
+ trigger.WaitOne();
+
+ Assert.IsNull(ex);
+ }
+
+ public static T GetVariable(CSharpScript a, string resultName) {
+ return (T)a.VariableStore[resultName];
+ }
+
+ public static string LoadScriptCodeFromFile(string scriptName) {
+ string path = Path.Combine(ScriptSourcesDirectory, scriptName + ScriptSourceFileExtension);
+ return File.ReadAllText(path);
+ }
+
+ public static void InitializeMainForm() {
+ MainFormManager.RegisterMainForm(new DockingMainForm());
+ var mainForm = MainFormManager.GetMainForm();
+ mainForm.ShowContentInViewHost = true;
+ }
+ }
+}
Index: /trunk/sources/HeuristicLab.Tests/HeuristicLab.Scripting-3.3/Scripts/GAQAPScriptTest.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/HeuristicLab.Scripting-3.3/Scripts/GAQAPScriptTest.cs (revision 11514)
+++ /trunk/sources/HeuristicLab.Tests/HeuristicLab.Scripting-3.3/Scripts/GAQAPScriptTest.cs (revision 11514)
@@ -0,0 +1,80 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using System.IO;
+using System.Linq;
+using HeuristicLab.Persistence.Default.Xml;
+using HeuristicLab.Problems.Instances.QAPLIB;
+using HeuristicLab.Problems.QuadraticAssignment;
+using HeuristicLab.Scripting;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace HeuristicLab.Tests {
+ [TestClass]
+ public class GAQAPScriptTest {
+ private const string ScriptFileName = "GA_QAP_Script";
+ private const string ScriptItemName = "Genetic Algorithm Script - QAP";
+ private const string ScriptItemDescription = "A scripted genetic algorithm which solves the \"" + ProblemInstanceName + "\" quadratic assignment problem (imported from Drezner)";
+ private const string ProblemInstanceName = "dre56";
+ private const string BestQualityVariableName = "bestQuality";
+
+ [TestMethod]
+ [TestCategory("Scripts.Create")]
+ [TestProperty("Time", "short")]
+ public void CreateGAQAPScriptScriptTest() {
+ var script = CreateGAQAPScript();
+ string path = Path.Combine(ScriptingUtils.ScriptsDirectory, ScriptFileName + ScriptingUtils.ScriptFileExtension);
+ XmlGenerator.Serialize(script, path);
+ }
+
+ [TestMethod]
+ [TestCategory("Scripts.Execute")]
+ [TestProperty("Time", "long")]
+ public void RunGAQAPScriptTest() {
+ var script = CreateGAQAPScript();
+
+ script.Compile();
+ ScriptingUtils.RunScript(script);
+
+ var bestQuality = ScriptingUtils.GetVariable(script, BestQualityVariableName);
+ Assert.AreEqual(2410.0, bestQuality, 1E-8);
+ }
+
+ private CSharpScript CreateGAQAPScript() {
+ var script = new CSharpScript {
+ Name = ScriptItemName,
+ Description = ScriptItemDescription
+ };
+ #region Variables
+ var provider = new DreznerQAPInstanceProvider();
+ var instance = provider.GetDataDescriptors().Single(x => x.Name == ProblemInstanceName);
+ var data = provider.LoadData(instance);
+ var problem = new QuadraticAssignmentProblem();
+ problem.Load(data);
+ script.VariableStore.Add(ProblemInstanceName, problem);
+ #endregion
+ #region Code
+ script.Code = ScriptingUtils.LoadScriptCodeFromFile(ScriptFileName);
+ #endregion
+ return script;
+ }
+ }
+}
Index: /trunk/sources/HeuristicLab.Tests/HeuristicLab.Scripting-3.3/Scripts/GUIAutomationScriptTest.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/HeuristicLab.Scripting-3.3/Scripts/GUIAutomationScriptTest.cs (revision 11514)
+++ /trunk/sources/HeuristicLab.Tests/HeuristicLab.Scripting-3.3/Scripts/GUIAutomationScriptTest.cs (revision 11514)
@@ -0,0 +1,73 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using System.IO;
+using System.Linq;
+using HeuristicLab.MainForm;
+using HeuristicLab.Optimization;
+using HeuristicLab.Persistence.Default.Xml;
+using HeuristicLab.Scripting;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace HeuristicLab.Tests {
+ [TestClass]
+ public class GUIAutomationScriptTest {
+ private const string ScriptFileName = "GUI_Automation_Script";
+ private const string ScriptItemName = "GUI Automation Script";
+ private const string ScriptItemDescription = "A script that runs a genetic algorithm on a traveling salesman problem with 5 different settings for population sizes and with 10 repetitions, then opens a bubble chart of the results and chooses the appropriate values for x and y axis automatically";
+ private const string ExperimentVariableName = "experiment";
+
+ [TestMethod]
+ [TestCategory("Scripts.Create")]
+ [TestProperty("Time", "short")]
+ public void CreateGUIAutomationScriptTest() {
+ var script = CreateGUIAutomationScript();
+ string path = Path.Combine(ScriptingUtils.ScriptsDirectory, ScriptFileName + ScriptingUtils.ScriptFileExtension);
+ XmlGenerator.Serialize(script, path);
+ }
+
+ [TestMethod]
+ [TestCategory("Scripts.Execute")]
+ [TestProperty("Time", "long")]
+ public void RunGUIAutomationScriptTest() {
+ var script = CreateGUIAutomationScript();
+
+ script.Compile();
+ ScriptingUtils.RunScript(script);
+
+ var experiment = ScriptingUtils.GetVariable(script, ExperimentVariableName);
+ var contentViews = MainFormManager.MainForm.Views.OfType().ToList();
+ Assert.IsNotNull(contentViews.SingleOrDefault(x => x.Content == experiment));
+ Assert.IsNotNull(contentViews.SingleOrDefault(x => x.Content == experiment.Runs));
+ }
+
+ private CSharpScript CreateGUIAutomationScript() {
+ var script = new CSharpScript {
+ Name = ScriptItemName,
+ Description = ScriptItemDescription
+ };
+ #region Code
+ script.Code = ScriptingUtils.LoadScriptCodeFromFile(ScriptFileName);
+ #endregion
+ return script;
+ }
+ }
+}
Index: /trunk/sources/HeuristicLab.Tests/HeuristicLab.Scripting-3.3/Scripts/GridSearchRFClassificationScriptTest.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/HeuristicLab.Scripting-3.3/Scripts/GridSearchRFClassificationScriptTest.cs (revision 11514)
+++ /trunk/sources/HeuristicLab.Tests/HeuristicLab.Scripting-3.3/Scripts/GridSearchRFClassificationScriptTest.cs (revision 11514)
@@ -0,0 +1,80 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using System.IO;
+using System.Linq;
+using HeuristicLab.Persistence.Default.Xml;
+using HeuristicLab.Problems.DataAnalysis;
+using HeuristicLab.Problems.Instances.DataAnalysis;
+using HeuristicLab.Scripting;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace HeuristicLab.Tests {
+ [TestClass]
+ public class GridSearchRFClassificationScriptTest {
+ private const string ScriptFileName = "GridSearch_RF_Classification_Script";
+ private const string ScriptItemName = "Grid Search Random Forest Script - Classification";
+ private const string ScriptItemDescription = "A script that runs a grid search for random forest parameters for solving symbolic classification problems";
+ private const string ProblemInstanceName = "Mammography, M. Elter, 2007";
+ private const string ProblemInstanceDataVaribleName = "problem";
+ private const string BestSolutionVariableName = "bestSolution";
+
+ [TestMethod]
+ [TestCategory("Scripts.Create")]
+ [TestProperty("Time", "short")]
+ public void CreateGridSearchRFClassificationScriptTest() {
+ var script = CreateGridSearchRFClassificationScript();
+ string path = Path.Combine(ScriptingUtils.ScriptsDirectory, ScriptFileName + ScriptingUtils.ScriptFileExtension);
+ XmlGenerator.Serialize(script, path);
+ }
+
+ [TestMethod]
+ [TestCategory("Scripts.Execute")]
+ [TestProperty("Time", "long")]
+ public void RunGridSearchRFClassificationScriptTest() {
+ var script = CreateGridSearchRFClassificationScript();
+
+ script.Compile();
+ ScriptingUtils.RunScript(script);
+
+ var bestSolution = ScriptingUtils.GetVariable(script, BestSolutionVariableName);
+ Assert.AreEqual(0.946957878315133, bestSolution.TrainingAccuracy, 1E-8);
+ Assert.AreEqual(0.734375, bestSolution.TestAccuracy, 1E-8);
+ }
+
+ private CSharpScript CreateGridSearchRFClassificationScript() {
+ var script = new CSharpScript {
+ Name = ScriptItemName,
+ Description = ScriptItemDescription
+ };
+ #region Variables
+ var provider = new UCIInstanceProvider();
+ var instance = (UCIDataDescriptor)provider.GetDataDescriptors().Single(x => x.Name == ProblemInstanceName);
+ var data = provider.LoadData(instance);
+ script.VariableStore.Add(ProblemInstanceDataVaribleName, data);
+ #endregion
+ #region Code
+ script.Code = ScriptingUtils.LoadScriptCodeFromFile(ScriptFileName);
+ #endregion
+ return script;
+ }
+ }
+}
Index: /trunk/sources/HeuristicLab.Tests/HeuristicLab.Scripting-3.3/Scripts/GridSearchRFRegressionScriptTest.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/HeuristicLab.Scripting-3.3/Scripts/GridSearchRFRegressionScriptTest.cs (revision 11514)
+++ /trunk/sources/HeuristicLab.Tests/HeuristicLab.Scripting-3.3/Scripts/GridSearchRFRegressionScriptTest.cs (revision 11514)
@@ -0,0 +1,80 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using System.IO;
+using System.Linq;
+using HeuristicLab.Persistence.Default.Xml;
+using HeuristicLab.Problems.DataAnalysis;
+using HeuristicLab.Problems.Instances.DataAnalysis;
+using HeuristicLab.Scripting;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace HeuristicLab.Tests {
+ [TestClass]
+ public class GridSearchRFRegressionScriptTest {
+ private const string ScriptFileName = "GridSearch_RF_Regression_Script";
+ private const string ScriptItemName = "Grid Search Random Forest Script - Regression";
+ private const string ScriptItemDescription = "A script that runs a grid search for random forest parameters for solving symbolic regression problems";
+ private const string ProblemInstanceName = "Keijzer 3 f(x) = 0.3 * x *sin(2 * PI * x); Interval [-3, 3]";
+ private const string ProblemInstanceDataVaribleName = "problem";
+ private const string BestSolutionVariableName = "bestSolution";
+
+ [TestMethod]
+ [TestCategory("Scripts.Create")]
+ [TestProperty("Time", "short")]
+ public void CreateGridSearchRFRegressionScriptTest() {
+ var script = CreateGridSearchRFRegressionScript();
+ string path = Path.Combine(ScriptingUtils.ScriptsDirectory, ScriptFileName + ScriptingUtils.ScriptFileExtension);
+ XmlGenerator.Serialize(script, path);
+ }
+
+ [TestMethod]
+ [TestCategory("Scripts.Execute")]
+ [TestProperty("Time", "long")]
+ public void RunGridSearchRFRegressionScriptTest() {
+ var script = CreateGridSearchRFRegressionScript();
+
+ script.Compile();
+ ScriptingUtils.RunScript(script);
+
+ var bestSolution = ScriptingUtils.GetVariable(script, BestSolutionVariableName);
+ Assert.AreEqual(1.0, bestSolution.TrainingRSquared, 1E-8);
+ Assert.AreEqual(0.966618401251492, bestSolution.TestRSquared, 1E-8);
+ }
+
+ private CSharpScript CreateGridSearchRFRegressionScript() {
+ var script = new CSharpScript {
+ Name = ScriptItemName,
+ Description = ScriptItemDescription
+ };
+ #region Variables
+ var provider = new KeijzerInstanceProvider();
+ var instance = (ArtificialRegressionDataDescriptor)provider.GetDataDescriptors().Single(x => x.Name == ProblemInstanceName);
+ var data = instance.GenerateRegressionData();
+ script.VariableStore.Add(ProblemInstanceDataVaribleName, data);
+ #endregion
+ #region Code
+ script.Code = ScriptingUtils.LoadScriptCodeFromFile(ScriptFileName);
+ #endregion
+ return script;
+ }
+ }
+}
Index: /trunk/sources/HeuristicLab.Tests/HeuristicLab.Scripting-3.3/Scripts/GridSearchSVMClassificationScriptTest.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/HeuristicLab.Scripting-3.3/Scripts/GridSearchSVMClassificationScriptTest.cs (revision 11514)
+++ /trunk/sources/HeuristicLab.Tests/HeuristicLab.Scripting-3.3/Scripts/GridSearchSVMClassificationScriptTest.cs (revision 11514)
@@ -0,0 +1,80 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using System.IO;
+using System.Linq;
+using HeuristicLab.Persistence.Default.Xml;
+using HeuristicLab.Problems.DataAnalysis;
+using HeuristicLab.Problems.Instances.DataAnalysis;
+using HeuristicLab.Scripting;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace HeuristicLab.Tests {
+ [TestClass]
+ public class GridSearchSVMClassificationScriptTest {
+ private const string ScriptFileName = "GridSearch_SVM_Classification_Script";
+ private const string ScriptItemName = "Grid Search SVM Script - Classification";
+ private const string ScriptItemDescription = "A script that runs a grid search for SVM parameters for solving symbolic classification problems";
+ private const string ProblemInstanceName = "Mammography, M. Elter, 2007";
+ private const string ProblemInstanceDataVaribleName = "problem";
+ private const string BestSolutionVariableName = "bestSolution";
+
+ [TestMethod]
+ [TestCategory("Scripts.Create")]
+ [TestProperty("Time", "short")]
+ public void CreateGridSearchSVMClassificationScriptTest() {
+ var script = CreateGridSearchSVMClassificationScript();
+ string path = Path.Combine(ScriptingUtils.ScriptsDirectory, ScriptFileName + ScriptingUtils.ScriptFileExtension);
+ XmlGenerator.Serialize(script, path);
+ }
+
+ [TestMethod]
+ [TestCategory("Scripts.Execute")]
+ [TestProperty("Time", "medium")]
+ public void RunGridSearchSVMClassificationScriptTest() {
+ var script = CreateGridSearchSVMClassificationScript();
+
+ script.Compile();
+ ScriptingUtils.RunScript(script);
+
+ var bestSolution = ScriptingUtils.GetVariable(script, BestSolutionVariableName);
+ Assert.AreEqual(0.817472698907956, bestSolution.TrainingAccuracy, 1E-8);
+ Assert.AreEqual(0.809375, bestSolution.TestAccuracy, 1E-8);
+ }
+
+ private CSharpScript CreateGridSearchSVMClassificationScript() {
+ var script = new CSharpScript {
+ Name = ScriptItemName,
+ Description = ScriptItemDescription
+ };
+ #region Variables
+ var provider = new UCIInstanceProvider();
+ var instance = (UCIDataDescriptor)provider.GetDataDescriptors().Single(x => x.Name == ProblemInstanceName);
+ var data = provider.LoadData(instance);
+ script.VariableStore.Add(ProblemInstanceDataVaribleName, data);
+ #endregion
+ #region Code
+ script.Code = ScriptingUtils.LoadScriptCodeFromFile(ScriptFileName);
+ #endregion
+ return script;
+ }
+ }
+}
Index: /trunk/sources/HeuristicLab.Tests/HeuristicLab.Scripting-3.3/Scripts/GridSearchSVMRegressionScriptTest.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/HeuristicLab.Scripting-3.3/Scripts/GridSearchSVMRegressionScriptTest.cs (revision 11514)
+++ /trunk/sources/HeuristicLab.Tests/HeuristicLab.Scripting-3.3/Scripts/GridSearchSVMRegressionScriptTest.cs (revision 11514)
@@ -0,0 +1,80 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using System.IO;
+using System.Linq;
+using HeuristicLab.Persistence.Default.Xml;
+using HeuristicLab.Problems.DataAnalysis;
+using HeuristicLab.Problems.Instances.DataAnalysis;
+using HeuristicLab.Scripting;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace HeuristicLab.Tests {
+ [TestClass]
+ public class GridSearchSVMRegressionScriptTest {
+ private const string ScriptFileName = "GridSearch_SVM_Regression_Script";
+ private const string ScriptItemName = "Grid Search SVM Script - Regression";
+ private const string ScriptItemDescription = "A script that runs a grid search for SVM parameters for solving symbolic regression problems";
+ private const string ProblemInstanceName = "Keijzer 3 f(x) = 0.3 * x *sin(2 * PI * x); Interval [-3, 3]";
+ private const string ProblemInstanceDataVaribleName = "problem";
+ private const string BestSolutionVariableName = "bestSolution";
+
+ [TestMethod]
+ [TestCategory("Scripts.Create")]
+ [TestProperty("Time", "short")]
+ public void CreateGridSearchSVMRegressionScriptTest() {
+ var script = CreateGridSearchSVMRegressionScript();
+ string path = Path.Combine(ScriptingUtils.ScriptsDirectory, ScriptFileName + ScriptingUtils.ScriptFileExtension);
+ XmlGenerator.Serialize(script, path);
+ }
+
+ [TestMethod]
+ [TestCategory("Scripts.Execute")]
+ [TestProperty("Time", "medium")]
+ public void RunGridSearchSVMRegressionScriptTest() {
+ var script = CreateGridSearchSVMRegressionScript();
+
+ script.Compile();
+ ScriptingUtils.RunScript(script);
+
+ var bestSolution = ScriptingUtils.GetVariable(script, BestSolutionVariableName);
+ Assert.AreEqual(0.0662219592243362, bestSolution.TrainingRSquared, 1E-8);
+ Assert.AreEqual(0.0794407638195434, bestSolution.TestRSquared, 1E-8);
+ }
+
+ private CSharpScript CreateGridSearchSVMRegressionScript() {
+ var script = new CSharpScript {
+ Name = ScriptItemName,
+ Description = ScriptItemDescription
+ };
+ #region Variables
+ var provider = new KeijzerInstanceProvider();
+ var instance = (ArtificialRegressionDataDescriptor)provider.GetDataDescriptors().Single(x => x.Name == ProblemInstanceName);
+ var data = instance.GenerateRegressionData();
+ script.VariableStore.Add(ProblemInstanceDataVaribleName, data);
+ #endregion
+ #region Code
+ script.Code = ScriptingUtils.LoadScriptCodeFromFile(ScriptFileName);
+ #endregion
+ return script;
+ }
+ }
+}
Index: /trunk/sources/HeuristicLab.Tests/HeuristicLab.Scripting-3.3/Scripts/OSGARastriginScriptTest.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/HeuristicLab.Scripting-3.3/Scripts/OSGARastriginScriptTest.cs (revision 11514)
+++ /trunk/sources/HeuristicLab.Tests/HeuristicLab.Scripting-3.3/Scripts/OSGARastriginScriptTest.cs (revision 11514)
@@ -0,0 +1,79 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using System.IO;
+using HeuristicLab.Data;
+using HeuristicLab.Persistence.Default.Xml;
+using HeuristicLab.Scripting;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace HeuristicLab.Tests {
+ [TestClass]
+ public class OSGARastriginScriptTest {
+ private const string ScriptFileName = "OSGA_Rastrigin_Script";
+ private const string ScriptItemName = "Offspring Selection Genetic Algorithm Script - Rastrigin";
+ private const string ScriptItemDescription = "A scripted offspring selection genetic algorithm that solves the 100-dimensional Rastrigin test function";
+ private const string LowerBoundVariableName = "minX";
+ private const string UpperBoundVariableName = "maxX";
+ private const string DimensionsVariableName = "N";
+ private const string SeedVariableName = "seed";
+ private const string BestQualityVariableName = "bestFitness";
+
+ [TestMethod]
+ [TestCategory("Scripts.Create")]
+ [TestProperty("Time", "short")]
+ public void CreateOSGARastriginScriptTest() {
+ var script = CreateOSGARastriginScript();
+ string path = Path.Combine(ScriptingUtils.ScriptsDirectory, ScriptFileName + ScriptingUtils.ScriptFileExtension);
+ XmlGenerator.Serialize(script, path);
+ }
+
+ [TestMethod]
+ [TestCategory("Scripts.Execute")]
+ [TestProperty("Time", "long")]
+ public void RunOSGARastriginScriptTest() {
+ var script = CreateOSGARastriginScript();
+
+ script.Compile();
+ ScriptingUtils.RunScript(script);
+
+ var bestQuality = ScriptingUtils.GetVariable(script, BestQualityVariableName);
+ Assert.AreEqual(0.176350329149955, bestQuality, 1E-8);
+ }
+
+ private CSharpScript CreateOSGARastriginScript() {
+ var script = new CSharpScript {
+ Name = ScriptItemName,
+ Description = ScriptItemDescription
+ };
+ #region Variables
+ script.VariableStore.Add(LowerBoundVariableName, new DoubleValue(-5.12));
+ script.VariableStore.Add(UpperBoundVariableName, new DoubleValue(5.12));
+ script.VariableStore.Add(DimensionsVariableName, new IntValue(100));
+ script.VariableStore.Add(SeedVariableName, new IntValue(0));
+ #endregion
+ #region Code
+ script.Code = ScriptingUtils.LoadScriptCodeFromFile(ScriptFileName);
+ #endregion
+ return script;
+ }
+ }
+}
Index: /trunk/sources/HeuristicLab.Tests/HeuristicLab.Tests.csproj
===================================================================
--- /trunk/sources/HeuristicLab.Tests/HeuristicLab.Tests.csproj (revision 11513)
+++ /trunk/sources/HeuristicLab.Tests/HeuristicLab.Tests.csproj (revision 11514)
@@ -102,5 +102,5 @@
-
+
..\bin\ALGLIB-3.7.0.dll
False
@@ -122,7 +122,7 @@
False
-
- False
+
..\bin\HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm-3.3.dll
+ False
@@ -150,5 +150,5 @@
False
-
+
..\bin\HeuristicLab.Analysis-3.3.dll
False
@@ -214,8 +214,11 @@
False
-
- False
+
+ ..\bin\HeuristicLab.Optimization.Views-3.3.dll
+ False
+
+
..\bin\HeuristicLab.Optimizer-3.3.dll
- True
+ False
@@ -259,7 +262,7 @@
False
-
- False
+
..\bin\HeuristicLab.Problems.GrammaticalEvolution-3.3.dll
+ False
@@ -327,6 +330,5 @@
False
-
- False
+
..\bin\HeuristicLab.Scripting-3.3.dll
False
@@ -338,4 +340,8 @@
..\bin\HeuristicLab.SequentialEngine-3.3.dll
+ False
+
+
+ ..\bin\LibSVM-3.12.dll
False
@@ -358,4 +364,5 @@
+
@@ -504,6 +511,34 @@
-
+
+
+
+
+
+
+
+
+
+ Always
+
+
+ Always
+
+
+ Always
+
+
+ Always
+
+
+ Always
+
+
+ Always
+
+
+ Always
+
Index: /trunk/sources/HeuristicLab.Tests/Test Resources/Script Sources/GA_QAP_Script.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/Test Resources/Script Sources/GA_QAP_Script.cs (revision 11514)
+++ /trunk/sources/HeuristicLab.Tests/Test Resources/Script Sources/GA_QAP_Script.cs (revision 11514)
@@ -0,0 +1,71 @@
+using System;
+using System.Linq;
+
+using HeuristicLab.Analysis;
+using HeuristicLab.Data;
+using HeuristicLab.Encodings.PermutationEncoding;
+using HeuristicLab.MainForm;
+using HeuristicLab.Problems.Instances.QAPLIB;
+using HeuristicLab.Problems.QuadraticAssignment;
+using HeuristicLab.Random;
+
+public class GAQAPScript : HeuristicLab.Scripting.CSharpScriptBase {
+ public override void Main() {
+ DateTime start = DateTime.UtcNow;
+
+ QuadraticAssignmentProblem qap;
+ if (vars.Contains("qap")) qap = vars.qap;
+ else {
+ var provider = new DreznerQAPInstanceProvider();
+ var instance = provider.GetDataDescriptors().Single(x => x.Name == "dre56");
+ var data = provider.LoadData(instance);
+ qap = new QuadraticAssignmentProblem();
+ qap.Load(data);
+ vars.qap = qap;
+ }
+
+ const uint seed = 0;
+ const int popSize = 100;
+ const int generations = 1000;
+ const double mutationRate = 0.05;
+
+ var random = new MersenneTwister(seed);
+ var population = new Permutation[popSize];
+ var qualities = new double[popSize];
+ var nextGen = new Permutation[popSize];
+ var nextQual = new double[popSize];
+
+ var qualityChart = new DataTable("Quality Chart");
+ var qualityRow = new DataRow("Best Quality");
+ qualityChart.Rows.Add(qualityRow);
+ vars.qualityChart = qualityChart;
+ MainFormManager.MainForm.ShowContent(qualityChart);
+
+ for (int i = 0; i < popSize; i++) {
+ population[i] = new Permutation(PermutationTypes.Absolute, qap.Weights.Rows, random);
+ qualities[i] = QAPEvaluator.Apply(population[i], qap.Weights, qap.Distances);
+ }
+ var bestQuality = qualities.Min();
+ var bestQualityGeneration = 0;
+
+ for (int g = 0; g < generations; g++) {
+ var parents = population.SampleProportional(random, 2 * popSize, qualities, windowing: true, inverseProportional: true).ToArray();
+ for (int i = 0; i < popSize; i++) {
+ nextGen[i] = PartiallyMatchedCrossover.Apply(random, parents[i * 2], parents[i * 2 + 1]);
+ if (random.NextDouble() < mutationRate) Swap2Manipulator.Apply(random, nextGen[i]);
+ nextQual[i] = QAPEvaluator.Apply(nextGen[i], qap.Weights, qap.Distances);
+ if (nextQual[i] < bestQuality) {
+ bestQuality = nextQual[i];
+ bestQualityGeneration = g;
+ }
+ }
+ qualityRow.Values.Add(bestQuality);
+ Array.Copy(nextGen, population, popSize);
+ Array.Copy(nextQual, qualities, popSize);
+ }
+
+ vars.elapsed = new TimeSpanValue(DateTime.UtcNow - start);
+ vars.bestQuality = bestQuality;
+ vars.bestQualityFoundAt = bestQualityGeneration;
+ }
+}
Index: /trunk/sources/HeuristicLab.Tests/Test Resources/Script Sources/GUI_Automation_Script.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/Test Resources/Script Sources/GUI_Automation_Script.cs (revision 11514)
+++ /trunk/sources/HeuristicLab.Tests/Test Resources/Script Sources/GUI_Automation_Script.cs (revision 11514)
@@ -0,0 +1,46 @@
+using System;
+using System.Linq;
+using System.Threading;
+using System.Windows.Forms;
+
+using HeuristicLab.Algorithms.GeneticAlgorithm;
+using HeuristicLab.Core;
+using HeuristicLab.MainForm;
+using HeuristicLab.MainForm.WindowsForms;
+using HeuristicLab.Optimization;
+using HeuristicLab.Optimization.Views;
+using HeuristicLab.Problems.TravelingSalesman;
+
+public class GUIAutomationScript : HeuristicLab.Scripting.CSharpScriptBase {
+ readonly ManualResetEvent mutex = new ManualResetEvent(false);
+
+ public override void Main() {
+ var ga = new GeneticAlgorithm {
+ MaximumGenerations = { Value = 50 },
+ PopulationSize = { Value = 10 },
+ Problem = new TravelingSalesmanProblem()
+ };
+
+ var experiment = new Experiment();
+ for (int i = 0; i < 5; i++) {
+ experiment.Optimizers.Add(new BatchRun() { Optimizer = (IOptimizer)ga.Clone(), Repetitions = 10 });
+ ga.PopulationSize.Value *= 2;
+ }
+
+ experiment.ExecutionStateChanged += OnExecutionStateChanged;
+ experiment.Start();
+ mutex.WaitOne();
+
+ vars.experiment = experiment;
+ MainFormManager.MainForm.ShowContent(experiment);
+ var viewHost = (ViewHost)MainFormManager.MainForm.ShowContent(experiment.Runs, typeof(RunCollectionBubbleChartView));
+ var bubbleChart = (UserControl)(viewHost.ActiveView);
+ bubbleChart.Controls.OfType().Single(x => x.Name == "yAxisComboBox").SelectedItem = "BestQuality";
+ bubbleChart.Controls.OfType().Single(x => x.Name == "xAxisComboBox").SelectedItem = "PopulationSize";
+ }
+
+ private void OnExecutionStateChanged(object sender, EventArgs e) {
+ if (((IExecutable)sender).ExecutionState == ExecutionState.Stopped)
+ mutex.Set();
+ }
+}
Index: /trunk/sources/HeuristicLab.Tests/Test Resources/Script Sources/GridSearch_RF_Classification_Script.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/Test Resources/Script Sources/GridSearch_RF_Classification_Script.cs (revision 11514)
+++ /trunk/sources/HeuristicLab.Tests/Test Resources/Script Sources/GridSearch_RF_Classification_Script.cs (revision 11514)
@@ -0,0 +1,74 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+using HeuristicLab.Algorithms.DataAnalysis;
+using HeuristicLab.Problems.DataAnalysis;
+using HeuristicLab.Problems.Instances.DataAnalysis;
+using HeuristicLab.Scripting;
+
+public class RFClassificationCrossValidationScript : HeuristicLab.Scripting.CSharpScriptBase {
+ /* Maximum degree of parallelism (specifies whether or not the grid search should be parallelized) */
+ const int maximumDegreeOfParallelism = 4;
+ /* Number of crossvalidation folds: */
+ const int numberOfFolds = 3;
+ /* Specify whether the folds should be shuffled before doing crossvalidation */
+ const bool shuffleFolds = true;
+
+ /* The tunable Random Forest parameters:
+ - "N" (number of trees). In the random forests literature, this is referred to as the ntree parameter.
+ Larger number of trees produce more stable models and covariate importance estimates, but require more memory and a longer run time.
+ For small datasets, 50 trees may be sufficient. For larger datasets, 500 or more may be required. Please consult the random forests
+ literature for extensive discussion of this parameter (e.g. Cutler et al., 2007; Strobl et al., 2007; Strobl et al., 2008).
+
+ - "R" The ratio of the training set that will be used in the construction of individual trees (0> randomForestParameterRanges = new Dictionary> {
+ { "N", ValueGenerator.GenerateSteps(5m, 10, 1).Select(x => Math.Pow(2,(double)x)) },
+ { "R", ValueGenerator.GenerateSteps(0.05m, 1, 0.05m).Select(x => (double)x) },
+ { "M", ValueGenerator.GenerateSteps(0.1m, 1, 0.1m).Select(x => (double)x) }
+ };
+
+ private static RandomForestClassificationSolution GridSearchWithCrossvalidation(IClassificationProblemData problemData, int numberOfCrossvalidationFolds, out RFParameter bestParameters,
+ int seed = 3141519) {
+ double rmsError, outOfBagRmsError, relClassificationError, outOfBagRelClassificationError;
+ bestParameters = RandomForestUtil.GridSearch(problemData, numberOfFolds, shuffleFolds, randomForestParameterRanges, seed, maximumDegreeOfParallelism);
+ var model = RandomForestModel.CreateClassificationModel(problemData, problemData.TrainingIndices, bestParameters.N, bestParameters.R, bestParameters.M, seed,
+ out rmsError, out outOfBagRmsError, out relClassificationError, out outOfBagRelClassificationError);
+ return (RandomForestClassificationSolution)model.CreateClassificationSolution(problemData);
+ }
+
+ private static RandomForestClassificationSolution GridSearch(IClassificationProblemData problemData, out RFParameter bestParameters, int seed = 3141519) {
+ double rmsError, outOfBagRmsError, relClassificationError, outOfBagRelClassificationError;
+ bestParameters = RandomForestUtil.GridSearch(problemData, randomForestParameterRanges, seed, maximumDegreeOfParallelism);
+ var model = RandomForestModel.CreateClassificationModel(problemData, problemData.TrainingIndices, bestParameters.N, bestParameters.R, bestParameters.M, seed,
+ out rmsError, out outOfBagRmsError, out relClassificationError, out outOfBagRelClassificationError);
+ return (RandomForestClassificationSolution)model.CreateClassificationSolution(problemData);
+ }
+
+ public override void Main() {
+ var variables = (Variables)vars;
+ var item = variables.SingleOrDefault(x => x.Value is IClassificationProblem || x.Value is IClassificationProblemData);
+ if (item.Equals(default(KeyValuePair)))
+ throw new ArgumentException("Could not find a suitable problem or problem data.");
+
+ string name = item.Key;
+ IClassificationProblemData problemData;
+ if (item.Value is IClassificationProblem)
+ problemData = ((IClassificationProblem)item.Value).ProblemData;
+ else
+ problemData = (IClassificationProblemData)item.Value;
+
+ var bestParameters = new RFParameter();
+ var bestSolution = GridSearch(problemData, out bestParameters);
+ vars["bestSolution"] = bestSolution;
+ vars["bestParameters"] = bestParameters;
+
+ Console.WriteLine("Accuracy (training): " + bestSolution.TrainingAccuracy + ", Accuracy (test): " + bestSolution.TestAccuracy);
+ Console.WriteLine("Model parameters: n = {0}, r = {1}, m = {2}", bestParameters.N, bestParameters.R, bestParameters.M);
+ }
+}
Index: /trunk/sources/HeuristicLab.Tests/Test Resources/Script Sources/GridSearch_RF_Regression_Script.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/Test Resources/Script Sources/GridSearch_RF_Regression_Script.cs (revision 11514)
+++ /trunk/sources/HeuristicLab.Tests/Test Resources/Script Sources/GridSearch_RF_Regression_Script.cs (revision 11514)
@@ -0,0 +1,74 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+using HeuristicLab.Algorithms.DataAnalysis;
+using HeuristicLab.Problems.DataAnalysis;
+using HeuristicLab.Problems.Instances.DataAnalysis;
+using HeuristicLab.Random;
+using HeuristicLab.Scripting;
+
+public class RFRegressionCrossValidationScript : HeuristicLab.Scripting.CSharpScriptBase {
+ /* Maximum degree of parallelism (specifies whether or not the grid search should be parallelized) */
+ const int maximumDegreeOfParallelism = 4;
+ /* Number of crossvalidation folds: */
+ const int numberOfFolds = 3;
+ /* Specify whether the crossvalidation folds should be shuffled */
+ const bool shuffleFolds = true;
+
+ /* The tunable Random Forest parameters:
+ - "n" (number of trees). In the random forests literature, this is referred to as the ntree parameter.
+ Larger number of trees produce more stable models and covariate importance estimates, but require more memory and a longer run time.
+ For small datasets, 50 trees may be sufficient. For larger datasets, 500 or more may be required. Please consult the random forests
+ literature for extensive discussion of this parameter (e.g. Cutler et al., 2007; Strobl et al., 2007; Strobl et al., 2008).
+
+ - "r" The ratio of the training set that will be used in the construction of individual trees (0> randomForestParameterRanges = new Dictionary> {
+ { "N", ValueGenerator.GenerateSteps(5m, 10, 1).Select(x => Math.Pow(2,(double)x)) },
+ { "R", ValueGenerator.GenerateSteps(0.05m, 1, 0.05m).Select(x => (double)x) },
+ { "M", ValueGenerator.GenerateSteps(0.1m, 1, 0.1m).Select(x => (double)x) }
+ };
+
+ private static RandomForestRegressionSolution GridSearchWithCrossvalidation(IRegressionProblemData problemData, out RFParameter bestParameters, int seed = 3141519) {
+ double rmsError, outOfBagRmsError, avgRelError, outOfBagAvgRelError;
+ bestParameters = RandomForestUtil.GridSearch(problemData, numberOfFolds, shuffleFolds, randomForestParameterRanges, seed, maximumDegreeOfParallelism);
+ var model = RandomForestModel.CreateRegressionModel(problemData, problemData.TrainingIndices, bestParameters.N, bestParameters.R, bestParameters.M, seed, out rmsError, out outOfBagRmsError, out avgRelError, out outOfBagAvgRelError);
+ return (RandomForestRegressionSolution)model.CreateRegressionSolution(problemData);
+ }
+
+ private static RandomForestRegressionSolution GridSearch(IRegressionProblemData problemData, out RFParameter bestParameters, int seed = 3141519) {
+ double rmsError, outOfBagRmsError, avgRelError, outOfBagAvgRelError;
+ var random = new MersenneTwister();
+ bestParameters = RandomForestUtil.GridSearch(problemData, randomForestParameterRanges, seed, maximumDegreeOfParallelism);
+ var model = RandomForestModel.CreateRegressionModel(problemData, problemData.TrainingIndices, bestParameters.N, bestParameters.R, bestParameters.M, seed,
+ out rmsError, out outOfBagRmsError, out avgRelError, out outOfBagAvgRelError);
+ return (RandomForestRegressionSolution)model.CreateRegressionSolution(problemData);
+ }
+
+ public override void Main() {
+ var variables = (Variables)vars;
+ var item = variables.SingleOrDefault(x => x.Value is IRegressionProblem || x.Value is IRegressionProblemData);
+ if (item.Equals(default(KeyValuePair)))
+ throw new ArgumentException("Could not find a suitable problem or problem data.");
+
+ string name = item.Key;
+ IRegressionProblemData problemData;
+ if (item.Value is IRegressionProblem)
+ problemData = ((IRegressionProblem)item.Value).ProblemData;
+ else
+ problemData = (IRegressionProblemData)item.Value;
+
+ var bestParameters = new RFParameter();
+ var bestSolution = GridSearch(problemData, out bestParameters);
+ vars["bestSolution"] = bestSolution;
+ vars["bestParameters"] = bestParameters;
+
+ Console.WriteLine("R2 (training): " + bestSolution.TrainingRSquared + ", R2 (test): " + bestSolution.TestRSquared);
+ Console.WriteLine("Model parameters: n = {0}, r = {1}, m = {2}", bestParameters.N, bestParameters.R, bestParameters.M);
+ }
+}
Index: /trunk/sources/HeuristicLab.Tests/Test Resources/Script Sources/GridSearch_SVM_Classification_Script.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/Test Resources/Script Sources/GridSearch_SVM_Classification_Script.cs (revision 11514)
+++ /trunk/sources/HeuristicLab.Tests/Test Resources/Script Sources/GridSearch_SVM_Classification_Script.cs (revision 11514)
@@ -0,0 +1,104 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Linq.Expressions;
+
+using HeuristicLab.Algorithms.DataAnalysis;
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+using HeuristicLab.Parameters;
+using HeuristicLab.Problems.DataAnalysis;
+using HeuristicLab.Problems.Instances.DataAnalysis;
+using HeuristicLab.Scripting;
+
+using LibSVM;
+
+public class SVMClassificationCrossValidationScript : HeuristicLab.Scripting.CSharpScriptBase {
+ /* Maximum degree of parallelism (specifies whether or not the grid search should be parallelized) */
+ const int maximumDegreeOfParallelism = 4;
+
+ /* Number of crossvalidation folds: */
+ const int numberOfFolds = 5;
+
+ /* Specify whether the folds should be shuffled */
+ const bool shuffleFolds = false;
+
+ /* The tunable SVM parameters:
+ - "C" (penalty factor) effects the trade-off between complexity and proportion of nonseparable samples and must be selected by the user. Can have any positive value.
+ - "nu" is an upper bound on the fraction of margin errors and a lower bound of the fraction of support vectors relative to the total number of training examples.
+ - "degree" represents the polynomial kernel degree
+ - "eps" (epsilon) determines the level of accuracy of the approximated function. It controls the width of the epsilon-insensitive zone used to fit the training data.
+ With optimal values of epsilon, the parameter C has negligible effect.
+ - "degree" represents the degree of the polynomial kernel
+ - "kernel_type" specifies the kernel to be used: linear, polynomial, radial basis or sigmoidal.
+ Valid values: svm_parameter.LINEAR, svm_parameter.POLY, svm_parameter.RBF, svm_parameter.SIGMOID
+ Comment or uncomment the parameter ranges below as needed. */
+
+ static Dictionary> svmParameterRanges = new Dictionary> {
+ { "svm_type", new List {svm_parameter.NU_SVC } },
+ { "kernel_type", new List { svm_parameter.RBF }},
+ { "C", ValueGenerator.GenerateSteps(-1m, 10, 1).Select(x => Math.Pow(2,(double)x)) },
+ { "gamma", ValueGenerator.GenerateSteps(-4m, -1, 1).Select(x => Math.Pow(2,(double)x)) },
+// { "eps", ValueGenerator.GenerateSteps(-8m, -1, 1).Select(x => Math.Pow(2, (double)x)) },
+// { "nu" , ValueGenerator.GenerateSteps(0m, 1, 0.05m).Select(x => Math.Pow(2, (double)x)) },
+// { "degree", ValueGenerator.GenerateSteps(1m, 4, 1).Select(x => (double)x) }
+ };
+
+ static Dictionary svmTypes = new Dictionary {
+ { svm_parameter.NU_SVC, "NU_SVC" },
+ { svm_parameter.C_SVC, "C_SVC" }
+ };
+
+ static Dictionary kernelTypes = new Dictionary {
+ { svm_parameter.LINEAR, "LINEAR" },
+ { svm_parameter.POLY, "POLY" },
+ { svm_parameter.RBF, "RBF" },
+ { svm_parameter.SIGMOID, "SIGMOID" }
+ };
+
+ private static SupportVectorClassificationSolution SvmGridSearch(IClassificationProblemData problemData, out svm_parameter bestParameters, out int nSv) {
+ bestParameters = SupportVectorMachineUtil.GridSearch(problemData, svmParameterRanges, numberOfFolds, shuffleFolds, maximumDegreeOfParallelism);
+ double trainingError, testError;
+ string svmType = svmTypes[bestParameters.svm_type];
+ string kernelType = kernelTypes[bestParameters.kernel_type];
+ var svm_solution = SupportVectorClassification.CreateSupportVectorClassificationSolution(problemData, problemData.AllowedInputVariables, svmType, kernelType,
+ bestParameters.C, bestParameters.nu, bestParameters.gamma, bestParameters.degree, out trainingError, out testError, out nSv);
+ return svm_solution;
+ }
+
+ public override void Main() {
+ var variables = (Variables)vars;
+ var item = variables.SingleOrDefault(x => x.Value is IClassificationProblem || x.Value is IClassificationProblemData);
+ if (item.Equals(default(KeyValuePair)))
+ throw new ArgumentException("Could not find a suitable problem or problem data.");
+
+ string name = item.Key;
+ IClassificationProblemData problemData;
+ if (item.Value is IClassificationProblem)
+ problemData = ((IClassificationProblem)item.Value).ProblemData;
+ else
+ problemData = (IClassificationProblemData)item.Value;
+
+ int nSv; // number of support vectors
+ svm_parameter bestParameters;
+ var bestSolution = SvmGridSearch(problemData, out bestParameters, out nSv);
+
+ vars["bestSolution"] = bestSolution;
+ Console.WriteLine(name + " parameters: C = {0}, g = {1:0.000}, eps = {2:0.000}, nu = {3:0.000}, degree = {4}", bestParameters.C, bestParameters.gamma, bestParameters.eps, bestParameters.nu, bestParameters.degree);
+ Console.WriteLine(name + " best solution accuracy (training): " + bestSolution.TrainingAccuracy + ", accuracy (test): " + bestSolution.TestAccuracy);
+
+ var bestParametersCollection = new ParameterCollection();
+ foreach (var p in svmParameterRanges.Keys) {
+ var getter = GenerateGetter(p);
+ bestParametersCollection.Add(new FixedValueParameter(p, new DoubleValue(getter(bestParameters))));
+ }
+ vars["bestParameters"] = bestParametersCollection;
+ }
+
+ private static Func GenerateGetter(string field) {
+ var paramExpr = Expression.Parameter(typeof(svm_parameter));
+ var getterExpr = Expression.Convert(Expression.Field(paramExpr, field), typeof(double)); // cast to double
+ Func f = Expression.Lambda>(getterExpr, paramExpr).Compile();
+ return f;
+ }
+}
Index: /trunk/sources/HeuristicLab.Tests/Test Resources/Script Sources/GridSearch_SVM_Regression_Script.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/Test Resources/Script Sources/GridSearch_SVM_Regression_Script.cs (revision 11514)
+++ /trunk/sources/HeuristicLab.Tests/Test Resources/Script Sources/GridSearch_SVM_Regression_Script.cs (revision 11514)
@@ -0,0 +1,105 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Linq.Expressions;
+
+using HeuristicLab.Algorithms.DataAnalysis;
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+using HeuristicLab.Parameters;
+using HeuristicLab.Problems.DataAnalysis;
+using HeuristicLab.Problems.Instances.DataAnalysis;
+using HeuristicLab.Scripting;
+
+using LibSVM;
+
+public class SVMRegressionCrossValidationScript : HeuristicLab.Scripting.CSharpScriptBase {
+ /* Maximum degree of parallelism (specifies whether or not the grid search should be parallelized) */
+ const int maximumDegreeOfParallelism = 4;
+
+ /* Number of crossvalidation folds: */
+ const int numberOfFolds = 5;
+
+ /* Specify whether the folds should be shuffled */
+ const bool shuffleFolds = false;
+
+ /* The tunable SVM parameters:
+ - "C" (penalty factor) effects the trade-off between complexity and proportion of nonseparable samples and must be selected by the user. Can have any positive value.
+ - "nu" is an upper bound on the fraction of margin errors and a lower bound of the fraction of support vectors relative to the total number of training examples.
+ - "degree" represents the polynomial kernel degree
+ - "eps" (epsilon) determines the level of accuracy of the approximated function. It controls the width of the epsilon-insensitive zone used to fit the training data.
+ With optimal values of epsilon, the parameter C has negligible effect.
+ - "degree" represents the degree of the polynomial kernel
+ - "kernel_type" specifies the kernel to be used: linear, polynomial, radial basis or sigmoidal.
+ Valid values: svm_parameter.LINEAR, svm_parameter.POLY, svm_parameter.RBF, svm_parameter.SIGMOID
+ Comment or uncomment the parameter ranges below as needed. */
+
+ static Dictionary> svmParameterRanges = new Dictionary> {
+ { "svm_type", new List {svm_parameter.NU_SVR } },
+ { "kernel_type", new List { svm_parameter.RBF }},
+ { "C", ValueGenerator.GenerateSteps(-1m, 10, 1).Select(x => Math.Pow(2, (double)x)) },
+ { "gamma", ValueGenerator.GenerateSteps(-4m, -1, 1).Select(x => Math.Pow(2, (double)x)) },
+// { "eps", ValueGenerator.GenerateSteps(-8m, -1, 1).Select(x => Math.Pow(2, (double)x)) },
+// { "nu" , ValueGenerator.GenerateSteps(0m, 1, 0.05m).Select(x => Math.Pow(2, (double)x)) },
+// { "degree", ValueGenerator.GenerateSteps(1m, 4, 1).Select(x => (double)x) }
+ };
+
+ static Dictionary svmTypes = new Dictionary {
+ { svm_parameter.NU_SVR, "NU_SVR" },
+ { svm_parameter.EPSILON_SVR, "EPSILON_SVR" }
+ };
+
+ static Dictionary kernelTypes = new Dictionary {
+ { svm_parameter.LINEAR, "LINEAR" },
+ { svm_parameter.POLY, "POLY" },
+ { svm_parameter.RBF, "RBF" },
+ { svm_parameter.SIGMOID, "SIGMOID" }
+ };
+
+ private static SupportVectorRegressionSolution SvmGridSearch(IRegressionProblemData problemData, out svm_parameter bestParameters, out int nSv) {
+ bestParameters = SupportVectorMachineUtil.GridSearch(problemData, svmParameterRanges, numberOfFolds, shuffleFolds, maximumDegreeOfParallelism);
+ double trainingError, testError;
+ string svmType = svmTypes[bestParameters.svm_type];
+ string kernelType = kernelTypes[bestParameters.kernel_type];
+ var svm_solution = SupportVectorRegression.CreateSupportVectorRegressionSolution(problemData, problemData.AllowedInputVariables, svmType, kernelType,
+ bestParameters.C, bestParameters.nu, bestParameters.gamma, bestParameters.eps, bestParameters.degree, out trainingError, out testError, out nSv);
+ return svm_solution;
+ }
+
+ public override void Main() {
+ var variables = (Variables)vars;
+ var item = variables.SingleOrDefault(x => x.Value is IRegressionProblem || x.Value is IRegressionProblemData);
+ if (item.Equals(default(KeyValuePair)))
+ throw new ArgumentException("Could not find a suitable problem or problem data.");
+
+ string name = item.Key;
+ IRegressionProblemData problemData;
+ if (item.Value is IRegressionProblem)
+ problemData = ((IRegressionProblem)item.Value).ProblemData;
+ else
+ problemData = (IRegressionProblemData)item.Value;
+
+ int nSv; // number of support vectors
+ svm_parameter bestParameters;
+ var bestSolution = SvmGridSearch(problemData, out bestParameters, out nSv);
+
+ vars["bestSolution"] = bestSolution;
+ Console.WriteLine(name + " parameters: C = {0}, g = {1:0.000}, eps = {2:0.000}, nu = {3:0.000}, degree = {4}", bestParameters.C, bestParameters.gamma, bestParameters.eps, bestParameters.nu, bestParameters.degree);
+ Console.WriteLine(name + " best solution mse (training): " + bestSolution.TrainingMeanSquaredError + ", mse (test): " + bestSolution.TestMeanSquaredError);
+ Console.WriteLine(name + " best solution R2 (training): " + bestSolution.TrainingRSquared + ", R2 (test): " + bestSolution.TestRSquared);
+
+ var bestParametersCollection = new ParameterCollection();
+ foreach (var p in svmParameterRanges.Keys) {
+ var getter = GenerateGetter(p);
+ bestParametersCollection.Add(new FixedValueParameter(p, new DoubleValue(getter(bestParameters))));
+ }
+ vars["bestParameters"] = bestParametersCollection;
+ }
+
+ private static Func GenerateGetter(string field) {
+ var paramExpr = Expression.Parameter(typeof(svm_parameter));
+ var getterExpr = Expression.Convert(Expression.Field(paramExpr, field), typeof(double)); // cast to double
+ Func f = Expression.Lambda>(getterExpr, paramExpr).Compile();
+ return f;
+ }
+}
Index: /trunk/sources/HeuristicLab.Tests/Test Resources/Script Sources/OSGA_Rastrigin_Script.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/Test Resources/Script Sources/OSGA_Rastrigin_Script.cs (revision 11514)
+++ /trunk/sources/HeuristicLab.Tests/Test Resources/Script Sources/OSGA_Rastrigin_Script.cs (revision 11514)
@@ -0,0 +1,111 @@
+using System;
+using System.Linq;
+
+public class OSGARastriginScript : HeuristicLab.Scripting.CSharpScriptBase {
+ public override void Main() {
+ int N = vars.N.Value;
+ double minX = vars.minX.Value;
+ double maxX = vars.maxX.Value;
+ int seed = vars.seed.Value;
+ var rand = new Random(seed);
+
+ var result = OSGA(rand, popSize: 1000, iterations: 5000, maxSelPres: 1000, mutationRate: 0.1,
+ obj: Rastrigin,
+ // x ~(i.i.d) U(0,1) * 10.24 - 5.12
+ creator: () => Enumerable.Range(1, N).Select(_ => rand.NextDouble() * (maxX - minX) + minX).ToArray(),
+ // random parent selection
+ selector: (f) => rand.Next(f.Length),
+ // single point crossover
+ crossover: (p0, p1, cand) => {
+ int cut = rand.Next(cand.Length);
+ Array.Copy(p0, cand, cut);
+ Array.Copy(p1, cut, cand, cut, cand.Length - cut);
+ },
+ // single point manipulation
+ manipulator: (p) => p[rand.Next(N)] = rand.NextDouble() * (maxX - minX) + minX,
+ output: true
+ );
+
+ double bestFit = result.Item2;
+ vars.bestFitness = bestFit;
+ Console.WriteLine("best fitness: {0}", bestFit);
+ }
+
+ private double Rastrigin(double[] x) {
+ return 10.0 * x.Length + x.Sum(xi => xi * xi - 10.0 * Math.Cos(2.0 * Math.PI * xi));
+ }
+
+ private Tuple OSGA(Random rand, int popSize, int iterations, double maxSelPres, double mutationRate, Func obj,
+ Func creator, Func selector, Action crossover, Action manipulator,
+ bool output = false)
+ where T : ICloneable {
+ // generate random pop
+ T[] pop = Enumerable.Range(0, popSize).Select(_ => creator()).ToArray();
+ // evaluate initial pop
+ double[] fit = pop.Select(p => obj(p)).ToArray();
+
+ // arrays for next pop (clone current pop because solutions are reused)
+ T[] popNew = pop.Select(pi => (T)pi.Clone()).ToArray();
+ double[] fitNew = new double[popSize];
+
+ var bestSolution = (T)pop.First().Clone(); // take a random solution (don't care)
+ double bestFit = fit.First();
+
+ // run generations
+ double curSelPres = 0;
+ for (int g = 0; g < iterations && curSelPres < maxSelPres; g++) {
+ // keep the first element as elite
+ int i = 1;
+ int genEvals = 0;
+ do {
+ var p1Idx = selector(fit);
+ var p2Idx = selector(fit);
+
+ var p1 = pop[p1Idx];
+ var p2 = pop[p2Idx];
+ var f1 = fit[p1Idx];
+ var f2 = fit[p2Idx];
+
+ // generate candidate solution (reuse old solutions)
+ crossover(p1, p2, popNew[i]);
+ // optional mutation
+ if (rand.NextDouble() < mutationRate) {
+ manipulator(popNew[i]);
+ }
+
+ double f = obj(popNew[i]);
+ genEvals++;
+ // if child is better than best (strict offspring selection)
+ if (f < Math.Min(f1, f2)) {
+ // update best fitness
+ if (f < bestFit) {
+ bestFit = f;
+ bestSolution = (T)popNew[i].Clone(); // overall best
+ }
+
+ // keep
+ fitNew[i] = f;
+ i++;
+ }
+
+ curSelPres = genEvals / (double)popSize;
+ } while (i < popNew.Length && curSelPres < maxSelPres);
+
+ Console.WriteLine("generation {0} obj {1:0.000} sel. pres. {2:###.0}", g, bestFit, curSelPres);
+
+ // swap
+ var tmpPop = pop;
+ var tmpFit = fit;
+ pop = popNew;
+ fit = fitNew;
+ popNew = tmpPop;
+ fitNew = tmpFit;
+
+ // keep elite
+ popNew[0] = (T)bestSolution.Clone();
+ fitNew[0] = bestFit;
+ }
+
+ return Tuple.Create(bestSolution, bestFit);
+ }
+}
Index: /trunk/sources/Test.cmd
===================================================================
--- /trunk/sources/Test.cmd (revision 11514)
+++ /trunk/sources/Test.cmd (revision 11514)
@@ -0,0 +1,29 @@
+@ECHO OFF
+
+SET /P BUILDBEFORETEST=Should the test project be rebuilt [n]:
+
+SET TESTCATEGORY=%~1
+
+IF "%TESTCATEGORY%"=="" SET TESTCATEGORY=Essential
+SET /P USERCATEGORY=Which category do you want to run [%TESTCATEGORY%]:
+IF "%USERCATEGORY%" NEQ "" SET TESTCATEGORY=%USERCATEGORY%
+
+set /P TESTPLATFORM=Which platform to run the tests [x64]:
+IF "%TESTPLATFORM%"=="" SET TESTPLATFORM=x64
+
+FOR /F "tokens=1,3 delims= " %%A IN ('REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\4.0"') DO (
+ IF "%%A"=="MSBuildToolsPath" SET MSBUILDPATH=%%B)
+
+IF "%BUILDBEFORETEST%" NEQ "" (
+ ECHO Building tests project ...
+ %MSBUILDPATH%msbuild.exe "HeuristicLab 3.3 Tests.sln" /target:Rebuild /p:Configuration="Debug",Platform="%TESTPLATFORM%" /m:2 /nologo /verbosity:q /clp:ErrorsOnly
+)
+
+ECHO Test starting for category %TESTCATEGORY%...
+
+FOR /F "tokens=1,2,* delims= " %%A IN ('REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\SxS\VS7"') DO (
+ IF "%%A"=="12.0" SET VSPATH=%%C)
+
+"%VSPATH%Common7\IDE\CommonExtensions\Microsoft\TestWindow\VSTest.Console.exe" bin\HeuristicLab.Tests.dll /Framework:framework40 /Platform:%TESTPLATFORM% /TestCaseFilter:"TestCategory=%TESTCATEGORY%"
+
+PAUSE