Changeset 8817
- Timestamp:
- 10/17/12 10:57:14 (12 years ago)
- Location:
- branches/OaaS
- Files:
-
- 38 added
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OaaS/HeuristicLab.Services.Optimization.Controller/HeuristicLab.Services.Optimization.ControllerService.csproj
r8545 r8817 131 131 </Reference> 132 132 <Reference Include="System" /> 133 <Reference Include="System.configuration" /> 133 134 <Reference Include="System.Core" /> 134 135 <Reference Include="System.Runtime.Serialization" /> … … 141 142 </ItemGroup> 142 143 <ItemGroup> 144 <Compile Include="HiveScenarioManagerOld.cs" /> 145 <Compile Include="HiveMapper.cs" /> 143 146 <Compile Include="HiveScenarioManager.cs" /> 147 <Compile Include="HLMapper.cs" /> 144 148 <Compile Include="Interfaces\IControllerService.cs" /> 145 149 <Compile Include="Interfaces\IScenarioManager.cs" /> … … 147 151 <Compile Include="PlaceholderControllerService.cs" /> 148 152 <Compile Include="Properties\AssemblyInfo.cs" /> 153 <Compile Include="ScenarioParser.cs" /> 149 154 <Compile Include="Utility.cs" /> 150 155 </ItemGroup> … … 153 158 </ItemGroup> 154 159 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> 160 <PropertyGroup> 161 <PreBuildEvent> 162 </PreBuildEvent> 163 </PropertyGroup> 155 164 <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 156 165 Other similar extension points exist, see Microsoft.Common.targets. -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/HiveScenarioManager.cs
r8545 r8817 15 15 using System.Threading; 16 16 using HeuristicLab.Data; 17 using System.IO; 17 18 18 19 namespace HeuristicLab.Services.Optimization.ControllerService { 19 20 public class HiveScenarioManager : IScenarioManager { 20 public object MapControllerDataType(object model, Parameter param) { 21 switch (param.Type) { 22 case ParameterType.Boolean: 23 return (param.Value as Model.BoolValue).Value; 24 case ParameterType.Integer: 25 return Convert.ToInt32((param.Value as Model.DecimalValue).Value); 26 case ParameterType.Percent: 27 case ParameterType.Decimal: 28 return (param.Value as Model.DecimalValue).Value; 29 case ParameterType.DecimalMatrix: 30 return Utility.ToMultiD(((param.Value as Model.DecimalMatrix).Value)); 31 case ParameterType.DecimalVector: 32 return (param.Value as Model.DecimalVector).Value; 33 case ParameterType.Type: 34 //TODO handle type correctly! 35 var typeValue = param.Value as Model.TypeValue; 36 37 IProblem problem = model as IProblem; 38 IAlgorithm algoModel = model as IAlgorithm; 39 if (problem == null && algoModel != null) { 40 problem = algoModel.Problem; 41 } 42 43 if (problem != null) { 44 var toselect = problem.Operators.OfType<IOperator>().FirstOrDefault(x => x.Name == typeValue.Value); 45 if (toselect != null) { 46 return toselect; 47 } 48 } 49 50 string parameterPropertyName = typeValue.Name.EndsWith("Parameter") ? typeValue.Name : typeValue.Name + "Parameter"; 51 var parameterProperty = model.GetType().GetProperty(parameterPropertyName); 52 if (parameterProperty != null) { 53 var parameterPropertyValue = parameterProperty.GetGetMethod().Invoke(model, null); 54 var vvProp = parameterPropertyValue.GetType().GetProperty("ValidValues"); 55 if (vvProp != null) { 56 //http://stackoverflow.com/questions/245607/how-is-generic-covariance-contra-variance-implemented-in-c-sharp-4-0 because of covariance declared in IEnumerable 57 var options = vvProp.GetGetMethod().Invoke(parameterPropertyValue, null) as IEnumerable<IItem>; 58 if (options != null) { 59 var result = options.FirstOrDefault(x => x.ItemName == typeValue.Value); 60 if (result != null) 61 return result; 62 } 63 } 64 } 65 66 Type type = null; 67 foreach (var asm in AppDomain.CurrentDomain.GetAssemblies()) { 68 type = asm.GetType(typeValue.Value); 69 if (type != null) 70 break; 71 } 72 73 return Activator.CreateInstance(type); 74 } 75 return null; 76 } 77 78 public object CreateHLObjectForType(object obj, Type type, Parameter prop) { 79 var value = MapControllerDataType(obj, prop); 80 if (prop.Type == ParameterType.Type) 81 return value; 82 83 if (type == typeof(HeuristicLab.Encodings.PermutationEncoding.Permutation)) { 84 double[] input = value as double[]; 85 int[] arr = new int[input.Length]; 86 for (int i = 0; i < input.Length; i++) { 87 arr[i] = Convert.ToInt32(input[i]); 88 } 89 var valueObj = new HeuristicLab.Encodings.PermutationEncoding.Permutation(Encodings.PermutationEncoding.PermutationTypes.RelativeUndirected, arr); 90 return valueObj; 91 } 92 var propertyGetter = obj.GetType().GetProperty(prop.Value.Name).GetGetMethod(); 93 return Activator.CreateInstance(propertyGetter.ReturnType, value); 94 } 95 96 private void MapProperty(object model, Parameter prop) { 97 var propertyGetter = model.GetType().GetProperty(prop.Value.Name).GetGetMethod(); 98 var propertySetter = model.GetType().GetProperty(prop.Value.Name).GetSetMethod(); 99 var value = propertyGetter.Invoke(model, null); 100 var valueProperty = value != null ? value.GetType().GetProperty("Value") : null; 101 if (propertySetter != null) { 102 var instance = CreateHLObjectForType(model, propertyGetter.ReturnType, prop); 103 propertySetter.Invoke(model, new object[] { instance }); 104 } 105 else if (valueProperty != null) { 106 valueProperty.GetSetMethod().Invoke(value, new object[] { MapControllerDataType(model, prop) }); 107 } 108 else { 109 Console.WriteLine("Failed to handle property!"); 110 } 21 private static IScenarioMapper tspMapper; 22 private static object lockable; 23 24 static HiveScenarioManager() { 25 lockable = new object(); 111 26 } 112 27 … … 114 29 Experiment experiment = new Experiment(); 115 30 var problem = new TravelingSalesmanProblem(); 116 foreach (var prop in scenario.InputParameters.Items) {117 MapProperty(problem, prop);118 }119 120 31 var algo = new GeneticAlgorithm(); 121 32 algo.Problem = problem; 122 foreach (var prop in scenario.AlgorithmParameters.Items) { 123 MapProperty(algo, prop); 124 } 33 34 MapExperiment(scenario, algo); 125 35 126 36 experiment.Optimizers.Add(algo); 127 37 SendExperimentToHive(user, experiment); 38 } 39 40 static public string AssemblyDirectory { 41 get { 42 string codeBase = Assembly.GetExecutingAssembly().CodeBase; 43 UriBuilder uri = new UriBuilder(codeBase); 44 string path = Uri.UnescapeDataString(uri.Path); 45 return Path.GetDirectoryName(path); 46 } 47 } 48 49 private IScenarioMapper GetMapper(Model.OptimizationScenario scenario) { 50 if (tspMapper == null) { 51 lock (lockable) { 52 if (tspMapper != null) 53 return tspMapper; 54 55 // http://stackoverflow.com/questions/3188882/compile-and-run-dynamic-code-without-generating-exe 56 using (var csCodeProvider = new Microsoft.CSharp.CSharpCodeProvider()) { 57 var cp = new System.CodeDom.Compiler.CompilerParameters() { 58 GenerateInMemory = true 59 }; 60 61 var referencedPaths = Directory.GetFiles(AssemblyDirectory, "*.dll"); 62 foreach (var loadedAssembly in referencedPaths) { 63 cp.ReferencedAssemblies.Add(loadedAssembly); 64 } 65 cp.ReferencedAssemblies.Add("System.dll"); 66 cp.ReferencedAssemblies.Add("System.Core.dll"); 67 cp.ReferencedAssemblies.Add("System.Data.dll"); 68 cp.ReferencedAssemblies.Add("System.Xml.dll"); 69 cp.ReferencedAssemblies.Add("System.Xml.Linq.dll"); 70 71 var res = csCodeProvider.CompileAssemblyFromSource( 72 cp, 73 @"using System; 74 using System.Collections.Generic; 75 using System.Linq; 76 using System.Text; 77 using HeuristicLab.Data; 78 using HeuristicLab.Services.Optimization.ControllerService.Model; 79 using HeuristicLab.Optimization; 80 using HeuristicLab.Services.Optimization.ControllerService; 81 using HeuristicLab.Algorithms.GeneticAlgorithm; 82 using HeuristicLab.Problems.TravelingSalesman; 83 public class TSPScenarioMapper : IScenarioMapper { 84 public void MapScenario(OptimizationScenario scenario, IAlgorithm algorithm) { 85 Console.WriteLine(""Mapping scenario!""); 86 var ga = algorithm as GeneticAlgorithm; 87 var problem = algorithm.Problem as TravelingSalesmanProblem; 88 89 problem.BestKnownQuality = HLMapper.ConvertToDoubleValue(scenario.InputParameters.FindByName(""BestKnownQuality"")); 90 problem.BestKnownSolution = HLMapper.ConvertToPermutation(scenario.InputParameters.FindByName(""BestKnownSolution"")); 91 problem.Coordinates = HLMapper.ConvertToDoubleMatrix(scenario.InputParameters.FindByName(""Coordinates"")); 92 var evalParam = HLMapper.GetStringValue(scenario.InputParameters.FindByName(""EvaluatorParameter"")); 93 if (evalParam == ""HeuristicLab.Problems.TravelingSalesman.TSPRoundedEuclideanPathEvaluator"") { 94 problem.EvaluatorParameter.Value = new TSPRoundedEuclideanPathEvaluator(); 95 } 96 else if (evalParam == ""HeuristicLab.Problems.TravelingSalesman.TSPGeoPathEvaluator"") { 97 problem.EvaluatorParameter.Value = new TSPGeoPathEvaluator(); 98 } 99 else { 100 problem.EvaluatorParameter.Value = new TSPEuclideanPathEvaluator(); 101 } 102 problem.UseDistanceMatrix = HLMapper.ConvertToBoolValue(scenario.InputParameters.FindByName(""UseDistanceMatrix"")); 103 Console.WriteLine(""Mapping algorithm...""); 104 ga.Mutator = HLMapper.FindInItemSet<HeuristicLab.Optimization.IManipulator>(ga.MutatorParameter.ValidValues, scenario.AlgorithmParameters.FindByName(""Mutator"")); 105 ga.CrossoverParameter.Value = HLMapper.FindOperator<HeuristicLab.Optimization.ICrossover>(problem, scenario.AlgorithmParameters.FindByName(""CrossoverParameter"")); 106 ga.Elites = HLMapper.ConvertToIntValue(scenario.AlgorithmParameters.FindByName(""Elites"")); 107 ga.MaximumGenerations = HLMapper.ConvertToIntValue(scenario.AlgorithmParameters.FindByName(""MaximumGenerations"")); 108 ga.MutationProbability = HLMapper.ConvertToPercentValue(scenario.AlgorithmParameters.FindByName(""MutationProbability"")); 109 ga.PopulationSize = HLMapper.ConvertToIntValue(scenario.AlgorithmParameters.FindByName(""PopulationSize"")); 110 ga.Seed = HLMapper.ConvertToIntValue(scenario.AlgorithmParameters.FindByName(""Seed"")); 111 ga.Selector = HLMapper.FindInItemSet<HeuristicLab.Optimization.ISelector>(ga.SelectorParameter.ValidValues, scenario.AlgorithmParameters.FindByName(""Selector"")); 112 ga.SetSeedRandomly = HLMapper.ConvertToBoolValue(scenario.AlgorithmParameters.FindByName(""SetSeedRandomly"")); 113 } 114 }" 115 ); 116 117 foreach (var error in res.Errors) { 118 Console.WriteLine(error); 119 } 120 121 var type = res.CompiledAssembly.GetType("TSPScenarioMapper"); 122 tspMapper = Activator.CreateInstance(type) as IScenarioMapper; 123 } // using 124 } // lock 125 } // if 126 return tspMapper; 127 } 128 129 private void MapExperiment(Model.OptimizationScenario scenario, IAlgorithm algorithm) { 130 IScenarioMapper mapper = GetMapper(scenario); 131 mapper.MapScenario(scenario, algorithm); 128 132 } 129 133 … … 246 250 return runs; 247 251 } 252 253 //TODO: We might need images / +++ 248 254 private Parameter MapHiveDataType(string name, IItem item) { 249 255 Parameter result = new Parameter(); -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/Model/ControllerModel.cs
r8545 r8817 80 80 81 81 public override bool TrySetFromString(string input) { 82 var splitted = input.Split(':'); 83 int index; 82 var splitted = input.Split(':'); 83 int index; 84 84 if (splitted.Length != 2) 85 85 return false; … … 191 191 set { items = value; } 192 192 } 193 194 public Parameter FindByName(string name) { 195 foreach (var param in items) { 196 if (param.Value.Name == name) { 197 return param; 198 } 199 } 200 return null; 201 } 193 202 } 194 203 … … 202 211 set { items = value; } 203 212 } 213 214 public Parameter FindByName(string name) { 215 foreach (var param in items) { 216 if (param.Value.Name == name) { 217 return param; 218 } 219 } 220 return null; 221 } 204 222 } 205 223 … … 208 226 [DataMember] 209 227 public string Name { get; set; } 228 229 [DataMember] 230 public string ProblemType { get; set; } 231 232 [DataMember] 233 public string AlgorithmType { get; set; } 234 235 [DataMember] 236 public string MapperType { get; set; } 210 237 211 238 private InputParameters inputParams = new InputParameters(); -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/PlaceholderControllerService.cs
r8545 r8817 5 5 using System.ServiceModel; 6 6 using HeuristicLab.Services.Optimization.ControllerService.Interfaces; 7 using HeuristicLab.Services.Optimization.ControllerService.Model; 7 8 8 9 namespace HeuristicLab.Services.Optimization.ControllerService { … … 12 13 private IList<Model.OptimizationScenario> scenarios; 13 14 15 private ScenarioParser parser = new ScenarioParser(); 16 14 17 private IScenarioManager hiveManager; 15 18 16 19 public PlaceholderControllerService() { 17 var tsp = new Model.OptimizationScenario() { Name = "Traveling Salesman Problem" };20 /*var tsp = new Model.OptimizationScenario() { Name = "Traveling Salesman Problem" }; 18 21 hiveManager = new HiveScenarioManager(); 19 22 tsp.InputParameters.Items.Add(new Model.Parameter() { Type = Model.ParameterType.Decimal, Value = new Model.DecimalValue() { Name = "BestKnownQuality", Value = 6110.0d } }); … … 46 49 tsp.AlgorithmParameters.Items.Add(new Model.Parameter() { Type = Model.ParameterType.Type, Value = new Model.TypeValue() { Name = "Selector", Value = "ProportionalSelector", Options = new string[] { "ProportionalSelector", "BestSelector" } } }); 47 50 tsp.AlgorithmParameters.Items.Add(new Model.Parameter() { Type = Model.ParameterType.Boolean, Value = new Model.BoolValue() { Name = "SetSeedRandomly", Value = true } });//, Value = true }); 48 this.scenarios = new List<Model.OptimizationScenario>() { tsp }; 51 this.scenarios = new List<Model.OptimizationScenario>() { tsp };*/ 49 52 //hiveManager.DispatchScenario(tsp); 53 hiveManager = new HiveScenarioManager(); 54 scenarios = parser.Scenarios; 55 //hiveManager.DispatchScenario(new User() { Username = "fschoeppl", Password = "fschoeppl" }, scenarios[0]); 50 56 } 51 57 -
branches/OaaS/HeuristicLab.Services.Optimization.ControllerService.Tests/HeuristicLab.Services.Optimization.ControllerService.Tests.csproj
r8545 r8817 36 36 </PropertyGroup> 37 37 <ItemGroup> 38 <Reference Include="ALGLIB-3.5.0, Version=3.5.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 39 <SpecificVersion>False</SpecificVersion> 40 <HintPath>..\bin\ALGLIB-3.5.0.dll</HintPath> 41 </Reference> 42 <Reference Include="HeuristicLab.Algorithms.GeneticAlgorithm-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 43 <SpecificVersion>False</SpecificVersion> 44 <HintPath>..\bin\HeuristicLab.Algorithms.GeneticAlgorithm-3.3.dll</HintPath> 45 </Reference> 46 <Reference Include="HeuristicLab.Collections-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 47 <SpecificVersion>False</SpecificVersion> 48 <HintPath>..\bin\HeuristicLab.Collections-3.3.dll</HintPath> 49 </Reference> 50 <Reference Include="HeuristicLab.Common-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 51 <SpecificVersion>False</SpecificVersion> 52 <HintPath>..\bin\HeuristicLab.Common-3.3.dll</HintPath> 53 </Reference> 54 <Reference Include="HeuristicLab.Common.Resources-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 55 <SpecificVersion>False</SpecificVersion> 56 <HintPath>..\bin\HeuristicLab.Common.Resources-3.3.dll</HintPath> 57 </Reference> 58 <Reference Include="HeuristicLab.Core-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 59 <SpecificVersion>False</SpecificVersion> 60 <HintPath>..\bin\HeuristicLab.Core-3.3.dll</HintPath> 61 </Reference> 62 <Reference Include="HeuristicLab.Data-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 63 <SpecificVersion>False</SpecificVersion> 64 <HintPath>..\bin\HeuristicLab.Data-3.3.dll</HintPath> 65 </Reference> 66 <Reference Include="HeuristicLab.Encodings.BinaryVectorEncoding-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 67 <SpecificVersion>False</SpecificVersion> 68 <HintPath>..\bin\HeuristicLab.Encodings.BinaryVectorEncoding-3.3.dll</HintPath> 69 </Reference> 70 <Reference Include="HeuristicLab.Encodings.IntegerVectorEncoding-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 71 <SpecificVersion>False</SpecificVersion> 72 <HintPath>..\bin\HeuristicLab.Encodings.IntegerVectorEncoding-3.3.dll</HintPath> 73 </Reference> 74 <Reference Include="HeuristicLab.Encodings.PermutationEncoding-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 75 <SpecificVersion>False</SpecificVersion> 76 <HintPath>..\bin\HeuristicLab.Encodings.PermutationEncoding-3.3.dll</HintPath> 77 </Reference> 78 <Reference Include="HeuristicLab.Encodings.RealVectorEncoding-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 79 <SpecificVersion>False</SpecificVersion> 80 <HintPath>..\bin\HeuristicLab.Encodings.RealVectorEncoding-3.3.dll</HintPath> 81 </Reference> 82 <Reference Include="HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4, Version=3.4.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 83 <SpecificVersion>False</SpecificVersion> 84 <HintPath>..\bin\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.dll</HintPath> 85 </Reference> 86 <Reference Include="HeuristicLab.Operators-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 87 <SpecificVersion>False</SpecificVersion> 88 <HintPath>..\bin\HeuristicLab.Operators-3.3.dll</HintPath> 89 </Reference> 90 <Reference Include="HeuristicLab.Optimization-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 91 <SpecificVersion>False</SpecificVersion> 92 <HintPath>..\bin\HeuristicLab.Optimization-3.3.dll</HintPath> 93 </Reference> 94 <Reference Include="HeuristicLab.Optimization.Operators-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 95 <SpecificVersion>False</SpecificVersion> 96 <HintPath>..\bin\HeuristicLab.Optimization.Operators-3.3.dll</HintPath> 97 </Reference> 98 <Reference Include="HeuristicLab.ParallelEngine-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 99 <SpecificVersion>False</SpecificVersion> 100 <HintPath>..\bin\HeuristicLab.ParallelEngine-3.3.dll</HintPath> 101 </Reference> 102 <Reference Include="HeuristicLab.Parameters-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 103 <SpecificVersion>False</SpecificVersion> 104 <HintPath>..\bin\HeuristicLab.Parameters-3.3.dll</HintPath> 105 </Reference> 106 <Reference Include="HeuristicLab.Persistence-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 107 <SpecificVersion>False</SpecificVersion> 108 <HintPath>..\bin\HeuristicLab.Persistence-3.3.dll</HintPath> 109 </Reference> 110 <Reference Include="HeuristicLab.PluginInfrastructure-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 111 <SpecificVersion>False</SpecificVersion> 112 <HintPath>..\bin\HeuristicLab.PluginInfrastructure-3.3.dll</HintPath> 113 </Reference> 114 <Reference Include="HeuristicLab.Problems.Instances-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 115 <SpecificVersion>False</SpecificVersion> 116 <HintPath>..\bin\HeuristicLab.Problems.Instances-3.3.dll</HintPath> 117 </Reference> 118 <Reference Include="HeuristicLab.Problems.TravelingSalesman-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 119 <SpecificVersion>False</SpecificVersion> 120 <HintPath>..\bin\HeuristicLab.Problems.TravelingSalesman-3.3.dll</HintPath> 121 </Reference> 122 <Reference Include="HeuristicLab.Problems.VehicleRouting-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 123 <SpecificVersion>False</SpecificVersion> 124 <HintPath>..\bin\HeuristicLab.Problems.VehicleRouting-3.3.dll</HintPath> 125 </Reference> 126 <Reference Include="HeuristicLab.Problems.VehicleRouting-3.4, Version=3.4.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 127 <SpecificVersion>False</SpecificVersion> 128 <HintPath>..\bin\HeuristicLab.Problems.VehicleRouting-3.4.dll</HintPath> 129 </Reference> 130 <Reference Include="HeuristicLab.Random-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 131 <SpecificVersion>False</SpecificVersion> 132 <HintPath>..\bin\HeuristicLab.Random-3.3.dll</HintPath> 133 </Reference> 134 <Reference Include="HeuristicLab.Tracing-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 135 <SpecificVersion>False</SpecificVersion> 136 <HintPath>..\bin\HeuristicLab.Tracing-3.3.dll</HintPath> 137 </Reference> 138 <Reference Include="IronPython"> 139 <HintPath>..\ip\IronPython.dll</HintPath> 140 </Reference> 141 <Reference Include="IronPython.Modules"> 142 <HintPath>..\ip\IronPython.Modules.dll</HintPath> 143 </Reference> 144 <Reference Include="Microsoft.Dynamic"> 145 <HintPath>..\ip\Microsoft.Dynamic.dll</HintPath> 146 </Reference> 147 <Reference Include="Microsoft.Scripting"> 148 <HintPath>..\ip\Microsoft.Scripting.dll</HintPath> 149 </Reference> 150 <Reference Include="Microsoft.Scripting.AspNet"> 151 <HintPath>..\ip\Microsoft.Scripting.AspNet.dll</HintPath> 152 </Reference> 153 <Reference Include="Microsoft.Scripting.Metadata"> 154 <HintPath>..\ip\Microsoft.Scripting.Metadata.dll</HintPath> 155 </Reference> 156 <Reference Include="Otis"> 157 <HintPath>..\otis\build\bin\Debug\Otis.dll</HintPath> 158 </Reference> 38 159 <Reference Include="System" /> 160 <Reference Include="System.Configuration" /> 39 161 <Reference Include="System.Core" /> 162 <Reference Include="System.Web.Extensions" /> 40 163 <Reference Include="System.Xml.Linq" /> 41 164 <Reference Include="System.Data.DataSetExtensions" /> … … 55 178 </ItemGroup> 56 179 <ItemGroup> 57 <None Include="app.config" /> 180 <None Include="app.config"> 181 <SubType>Designer</SubType> 182 </None> 183 <None Include="mappings\mapping.py" /> 184 <None Include="mappings\scenario.xsd"> 185 <SubType>Designer</SubType> 186 </None> 187 </ItemGroup> 188 <ItemGroup> 189 <Content Include="mappings\mapping.tsp.xml" /> 190 <Content Include="mappings\tsp.xml" /> 58 191 </ItemGroup> 59 192 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> 193 <PropertyGroup> 194 <PostBuildEvent>mkdir $(TargetDir)\mappings 195 copy $(ProjectDir)\mappings\* $(TargetDir)\mappings</PostBuildEvent> 196 </PropertyGroup> 60 197 <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 61 198 Other similar extension points exist, see Microsoft.Common.targets. -
branches/OaaS/HeuristicLab.Services.Optimization.ControllerService.Tests/Program.cs
r8545 r8817 4 4 using System.Text; 5 5 using HeuristicLab.Services.Optimization.ControllerService.Interfaces; 6 using HeuristicLab.Problems.TravelingSalesman; 7 using System.Reflection; 8 using System.IO; 9 using Microsoft.Scripting.Hosting; 10 using IronPython.Hosting; 11 using HeuristicLab.Algorithms.GeneticAlgorithm; 12 using HeuristicLab.Persistence.Core; 13 using HeuristicLab.Core; 6 14 7 15 namespace HeuristicLab.Services.Optimization.ControllerService.Tests { 8 16 class Program { 9 17 static void Main(string[] args) { 18 Console.WriteLine(AppDomain.CurrentDomain.BaseDirectory); 19 //TestScenarioParser(); 20 TestCodeDOM(); 21 //TestPython(); 22 //TestOtis(); 23 //TestJobResults(); 24 } 25 26 static void TestJobResults() { 10 27 IScenarioManager manager = new HiveScenarioManager(); 11 28 Console.WriteLine("Press key to continue"); … … 16 33 } 17 34 } 35 36 static void TestStorable() { 37 TravelingSalesmanProblem tsp = new TravelingSalesmanProblem(); 38 GeneticAlgorithm algo = new GeneticAlgorithm(); 39 algo.Problem = tsp; 40 41 42 } 43 44 static void TestCodeDOM() { 45 ScenarioParser parser = new ScenarioParser(); 46 var scen = parser.GetByName("Traveling Salesman Problem"); 47 TravelingSalesmanProblem tsp = new TravelingSalesmanProblem(); 48 GeneticAlgorithm algo = new GeneticAlgorithm(); 49 algo.Problem = tsp; 50 51 // http://stackoverflow.com/questions/3188882/compile-and-run-dynamic-code-without-generating-exe 52 using (var csCodeProvider = new Microsoft.CSharp.CSharpCodeProvider()) { 53 54 var cp = new System.CodeDom.Compiler.CompilerParameters() { 55 GenerateInMemory = true 56 }; 57 58 var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies().ToList(); 59 var loadedPaths = loadedAssemblies.Select(a => a.Location).ToArray(); 60 61 var referencedPaths = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.dll"); 62 foreach (var loadedAssembly in referencedPaths) { 63 cp.ReferencedAssemblies.Add(loadedAssembly); 64 } 65 cp.ReferencedAssemblies.Add("System.dll"); 66 67 tsp.BestKnownQuality = HLMapper.ConvertToDoubleValue(scen.InputParameters.FindByName("BestKnownQuality")); 68 69 var res = csCodeProvider.CompileAssemblyFromSource( 70 cp 71 , 72 @"using System; 73 using System.Collections.Generic; 74 using System.Linq; 75 using System.Text; 76 using HeuristicLab.Data; 77 using HeuristicLab.Services.Optimization.ControllerService.Model; 78 using HeuristicLab.Optimization; 79 using HeuristicLab.Services.Optimization.ControllerService; 80 using HeuristicLab.Algorithms.GeneticAlgorithm; 81 using HeuristicLab.Problems.TravelingSalesman; 82 public class TSPScenarioMapper : IScenarioMapper { 83 public void MapScenario(OptimizationScenario scenario, IAlgorithm algorithm) { 84 Console.WriteLine(""Mapping scenario!""); 85 var ga = algorithm as GeneticAlgorithm; 86 var problem = algorithm.Problem as TravelingSalesmanProblem; 87 88 problem.BestKnownQuality = HLMapper.ConvertToDoubleValue(scenario.InputParameters.FindByName(""BestKnownQuality"")); 89 problem.BestKnownSolution = HLMapper.ConvertToPermutation(scenario.InputParameters.FindByName(""BestKnownSolution"")); 90 problem.Coordinates = HLMapper.ConvertToDoubleMatrix(scenario.InputParameters.FindByName(""Coordinates"")); 91 var evalParam = HLMapper.GetStringValue(scenario.InputParameters.FindByName(""EvaluatorParameter"")); 92 if (evalParam == ""HeuristicLab.Problems.TravelingSalesman.TSPRoundedEuclideanPathEvaluator"") { 93 problem.EvaluatorParameter.Value = new TSPRoundedEuclideanPathEvaluator(); 94 } 95 else if (evalParam == ""HeuristicLab.Problems.TravelingSalesman.TSPGeoPathEvaluator"") { 96 problem.EvaluatorParameter.Value = new TSPGeoPathEvaluator(); 97 } 98 else { 99 problem.EvaluatorParameter.Value = new TSPEuclideanPathEvaluator(); 100 } 101 problem.UseDistanceMatrix = HLMapper.ConvertToBoolValue(scenario.InputParameters.FindByName(""UseDistanceMatrix"")); 102 Console.WriteLine(""Mapping algorithm...""); 103 ga.Mutator = HLMapper.FindInItemSet<HeuristicLab.Optimization.IManipulator>(ga.MutatorParameter.ValidValues, scenario.AlgorithmParameters.FindByName(""Mutator"")); 104 ga.CrossoverParameter.Value = HLMapper.FindOperator<HeuristicLab.Optimization.ICrossover>(problem, scenario.AlgorithmParameters.FindByName(""CrossoverParameter"")); 105 ga.Elites = HLMapper.ConvertToIntValue(scenario.AlgorithmParameters.FindByName(""Elites"")); 106 ga.MaximumGenerations = HLMapper.ConvertToIntValue(scenario.AlgorithmParameters.FindByName(""MaximumGenerations"")); 107 ga.MutationProbability = HLMapper.ConvertToPercentValue(scenario.AlgorithmParameters.FindByName(""MutationProbability"")); 108 ga.PopulationSize = HLMapper.ConvertToIntValue(scenario.AlgorithmParameters.FindByName(""PopulationSize"")); 109 ga.Seed = HLMapper.ConvertToIntValue(scenario.AlgorithmParameters.FindByName(""Seed"")); 110 ga.Selector = HLMapper.FindInItemSet<HeuristicLab.Optimization.ISelector>(ga.SelectorParameter.ValidValues, scenario.AlgorithmParameters.FindByName(""Selector"")); 111 ga.SetSeedRandomly = HLMapper.ConvertToBoolValue(scenario.AlgorithmParameters.FindByName(""SetSeedRandomly"")); 112 } 113 }" 114 ); 115 116 foreach (var error in res.Errors) { 117 Console.WriteLine(error); 118 } 119 120 var type = res.CompiledAssembly.GetType("TSPScenarioMapper"); 121 var mapper = Activator.CreateInstance(type) as IScenarioMapper; 122 mapper.MapScenario(scen, algo); 123 } 124 } 125 126 static void TestPython() { 127 ScenarioParser parser = new ScenarioParser(); 128 var scen = parser.GetByName("Traveling Salesman Problem"); 129 //TravelingSalesmanProblem tsp = new TravelingSalesmanProblem(); 130 //GeneticAlgorithm algo = new GeneticAlgorithm(); 131 //algo.Problem = tsp; 132 var rt = Python.CreateRuntime(); 133 // workaround to load all referenced assemblies into the current AppDomain 134 var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies().ToList(); 135 var loadedPaths = loadedAssemblies.Select(a => a.Location).ToArray(); 136 137 var referencedPaths = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.dll"); 138 var toLoad = referencedPaths.Where(r => !loadedPaths.Contains(r, StringComparer.InvariantCultureIgnoreCase)).ToList(); 139 toLoad.ForEach(path => loadedAssemblies.Add(AppDomain.CurrentDomain.Load(AssemblyName.GetAssemblyName(path)))); 140 141 foreach (var assm in AppDomain.CurrentDomain.GetAssemblies()) { 142 rt.LoadAssembly(assm); 143 } 144 145 /*var scope = rt.CreateScope(); 146 scope.SetVariable("source", scen); 147 scope.SetVariable("target", tsp);*/ 148 var engine = rt.GetEngine("py"); 149 char op = ' '; 150 while (op != 'q') { 151 try { 152 TravelingSalesmanProblem tsp = new TravelingSalesmanProblem(); 153 GeneticAlgorithm algo = new GeneticAlgorithm(); 154 algo.Problem = tsp; 155 Console.WriteLine("\n\n==============================================================="); 156 var script = engine.CreateScriptSourceFromFile(System.Configuration.ConfigurationManager.AppSettings["scenarioPath"] + @"\mapping.py"); 157 var scope = engine.CreateScope(); 158 scope.SetVariable("source", scen); 159 scope.SetVariable("problem", tsp); 160 scope.SetVariable("algorithm", algo); 161 script.Execute(scope); 162 } 163 catch (Exception e) { 164 Console.WriteLine(e); 165 } 166 Console.WriteLine("Hit 'q' to quit..."); 167 op = Console.ReadKey().KeyChar; 168 } 169 170 /*dynamic script = rt.UseFile("C:/temp/scenarios/mapping.py"); 171 script.SetVariable("source", scen); 172 script.SetVariable("target", tsp); 173 174 175 script.mapObjects(scen, tsp);*/ 176 177 } 178 179 static void TestOtis() { 180 Console.WriteLine(); 181 Otis.Configuration cfg = new Otis.Configuration(); 182 Model.DecimalValue dv = new Model.DecimalValue(); 183 dv.Value = 100; 184 Console.WriteLine(dv); 185 Console.WriteLine(typeof(HeuristicLab.Data.DoubleValue).AssemblyQualifiedName); 186 Console.WriteLine(typeof(System.Double).AssemblyQualifiedName); 187 188 // workaround to load all referenced assemblies into the current AppDomain 189 var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies().ToList(); 190 var loadedPaths = loadedAssemblies.Select(a => a.Location).ToArray(); 191 192 var referencedPaths = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.dll"); 193 var toLoad = referencedPaths.Where(r => !loadedPaths.Contains(r, StringComparer.InvariantCultureIgnoreCase)).ToList(); 194 toLoad.ForEach(path => loadedAssemblies.Add(AppDomain.CurrentDomain.Load(AssemblyName.GetAssemblyName(path)))); 195 196 foreach (var assm in AppDomain.CurrentDomain.GetAssemblies()) { 197 //cfg.AddAssembly(assm); 198 cfg.AddAssemblyReference(assm); 199 } 200 //cfg.AddAssemblyReference("HeuristicLab.Data-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec"); 201 //cfg.AddAssemblyReference("HeuristicLab.Data-3.3.dll"); 202 cfg.AddXmlFile(System.Configuration.ConfigurationManager.AppSettings["scenarioPath"] + @"\mapping.tsp.xml"); 203 204 Otis.IAssembler<TravelingSalesmanProblem,Model.OptimizationScenario> asm = cfg.GetAssembler<TravelingSalesmanProblem,Model.OptimizationScenario>(); 205 ScenarioParser parser = new ScenarioParser(); 206 var scen = parser.GetByName("Traveling Salesman Problem"); 207 TravelingSalesmanProblem tsp = new TravelingSalesmanProblem(); 208 //tsp.BestKnownQuality = new Data.DoubleValue(); 209 asm.Assemble(ref tsp, ref scen); 210 Console.WriteLine(tsp.BestKnownQuality); 211 } 212 213 static void TestMapping() { 214 } 215 216 // template for mapping Model.OptimizationScenario & e.g. TSP 217 static void TestScenarioParser() { 218 ScenarioParser parser = new ScenarioParser(); 219 var scen = parser.GetByName("Traveling Salesman Problem"); 220 TravelingSalesmanProblem tsp = new TravelingSalesmanProblem(); 221 // proceed with mapping between scen and tsp 222 } 18 223 } 19 224 } -
branches/OaaS/HeuristicLab.Services.Optimization.ControllerService.Tests/app.config
r8545 r8817 1 1 <?xml version="1.0"?> 2 2 <configuration> 3 <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup> 3 <startup> 4 <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" /> 5 </startup> 4 6 <system.serviceModel> 5 7 <diagnostics> … … 51 53 </behavior> 52 54 </endpointBehaviors> 53 </behaviors> 55 </behaviors> 54 56 <client> 55 57 <endpoint address="http://127.0.0.1:8080/ControllerService.svc" behaviorConfiguration="LocalCertValidation" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IControllerService" contract="HeuristicLab.Services.Optimization.ControllerService.IControllerService" name="WSHttpBinding_IControllerService"> … … 73 75 </client> 74 76 </system.serviceModel> 77 <appSettings> 78 <!-- 79 <add key="scenarioPath" value="C:\temp\scenarios" /> 80 <add key="scenarioSchemaPath" value="C:\temp\scenarios\scenario.xsd" /> 81 --> 82 <!-- Adjust paths to your mappings folder --> 83 <add key="scenarioPath" value="C:\dev\Heuristiclab\branches\OaaS\HeuristicLab.Services.Optimization.ControllerService.Tests\mappings" /> 84 <add key="scenarioSchemaPath" value="C:\dev\Heuristiclab\branches\OaaS\HeuristicLab.Services.Optimization.ControllerService.Tests\mappings\scenario.xsd" /> 85 <add key="ClientSettingsProvider.ServiceUri" value="" /> 86 </appSettings> 87 <system.web> 88 <membership defaultProvider="ClientAuthenticationMembershipProvider"> 89 <providers> 90 <add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" /> 91 </providers> 92 </membership> 93 <roleManager defaultProvider="ClientRoleProvider" enabled="true"> 94 <providers> 95 <add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" /> 96 </providers> 97 </roleManager> 98 </system.web> 75 99 </configuration> -
branches/OaaS/HeuristicLab.Services.Optimization.Web/HeuristicLab.Services.Optimization.Web.csproj
r8545 r8817 25 25 <ErrorReport>prompt</ErrorReport> 26 26 <WarningLevel>4</WarningLevel> 27 <FilesToIncludeForPublish>AllFilesInProjectFolder</FilesToIncludeForPublish> 27 28 </PropertyGroup> 28 29 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> … … 136 137 <Content Include="Global.asax" /> 137 138 <Content Include="ControllerService.svc" /> 139 <Content Include="Mappings\tsp.xml" /> 138 140 <Content Include="Scripts\jquery-1.5.1-vsdoc.js" /> 139 141 <Content Include="Scripts\jquery-1.5.1.js" /> … … 146 148 <Content Include="Scripts\modernizr-1.7.js" /> 147 149 <Content Include="Scripts\modernizr-1.7.min.js" /> 148 <Content Include="Web.config" /> 150 <Content Include="Web.config"> 151 <SubType>Designer</SubType> 152 </Content> 149 153 <Content Include="Web.Debug.config"> 150 154 <DependentUpon>Web.config</DependentUpon> … … 247 251 <ItemGroup> 248 252 <Content Include="Views\Optimization\JobDetails.cshtml" /> 253 </ItemGroup> 254 <ItemGroup> 255 <None Include="Mappings\mapping.py" /> 256 <None Include="Mappings\scenario.xsd"> 257 <SubType>Designer</SubType> 258 </None> 249 259 </ItemGroup> 250 260 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> -
branches/OaaS/HeuristicLab.Services.Optimization.Web/Views/Shared/DisplayTemplates/DecimalMatrix.cshtml
r8506 r8817 7 7 @for (int i = 0; i < Model.Value.Length; i++) { 8 8 <tr> 9 @for (int j = 0; j < Model.Value[ j].Length; j++) {9 @for (int j = 0; j < Model.Value[i].Length; j++) { 10 10 <td> 11 11 @Model.Value[i][j] -
branches/OaaS/HeuristicLab.Services.Optimization.Web/Views/Shared/EditorTemplates/DecimalMatrix.cshtml
r8506 r8817 7 7 @for (int i = 0; i < Model.Value.Length; i++) { 8 8 <tr> 9 @for (int j = 0; j < Model.Value[ j].Length; j++) {9 @for (int j = 0; j < Model.Value[i].Length; j++) { 10 10 <td> 11 11 @Html.Raw(Html.TextBoxFor(model => Model.Value[i][j]).ToString().Replace("itm.Value.Value[" + i + "][" + j + "]", Model.Name + "_" + i + "_" + j)) -
branches/OaaS/HeuristicLab.Services.Optimization/HeuristicLab.Services.Optimization.ccproj
r8384 r8817 55 55 </ProjectReference> 56 56 </ItemGroup> 57 <ItemGroup> 58 <Folder Include="HeuristicLab.Services.Hive.WebRoleContent\" /> 59 </ItemGroup> 57 60 <!-- Import the target files for this project template --> 58 61 <PropertyGroup> -
branches/OaaS/HeuristicLab.Services.Optimization/ServiceConfiguration.Cloud.cscfg
r8384 r8817 27 27 <Certificates> 28 28 <Certificate name="Microsoft.WindowsAzure.Plugins.RemoteAccess.PasswordEncryption" thumbprint="5D180FD78AB82CA765690BBADC60014C6D4A88CA" thumbprintAlgorithm="sha1" /> 29 <Certificate name="localhost" thumbprint="0F3B035DAC806C637B8E7A5BC957D8D30CFD6057" thumbprintAlgorithm="sha1" /> 29 30 </Certificates> 30 31 </Role> -
branches/OaaS/HeuristicLab.Services.Optimization/ServiceConfiguration.Local.cscfg
r8384 r8817 27 27 <Certificates> 28 28 <Certificate name="Microsoft.WindowsAzure.Plugins.RemoteAccess.PasswordEncryption" thumbprint="5D180FD78AB82CA765690BBADC60014C6D4A88CA" thumbprintAlgorithm="sha1" /> 29 <Certificate name="localhost" thumbprint="0F3B035DAC806C637B8E7A5BC957D8D30CFD6057" thumbprintAlgorithm="sha1" /> 29 30 </Certificates> 30 31 </Role> -
branches/OaaS/HeuristicLab.Services.Optimization/ServiceDefinition.build.csdef
r8384 r8817 32 32 <Certificate name="localhost" storeLocation="LocalMachine" storeName="My" /> 33 33 </Certificates> 34 <Contents> 35 <Content destination=".\"> 36 <SourceDirectory path="rcf/Debug/HeuristicLab.Services.Hive.WebRoleContent\" /> 37 </Content> 38 </Contents> 34 39 </WebRole> 35 40 <WebRole name="HeuristicLab.Services.Optimization.Web" vmsize="Small"> … … 48 53 <Import moduleName="RemoteAccess" /> 49 54 </Imports> 55 <Certificates> 56 <Certificate name="localhost" storeLocation="LocalMachine" storeName="My" /> 57 </Certificates> 50 58 </WebRole> 51 59 </ServiceDefinition> -
branches/OaaS/HeuristicLab.Services.Optimization/ServiceDefinition.csdef
r8384 r8817 39 39 <Import moduleName="RemoteAccess" /> 40 40 </Imports> 41 <Certificates> 42 <Certificate name="localhost" storeLocation="LocalMachine" storeName="My" /> 43 </Certificates> 41 44 </WebRole> 42 45 </ServiceDefinition>
Note: See TracChangeset
for help on using the changeset viewer.