- Timestamp:
- 12/17/12 09:37:16 (12 years ago)
- Location:
- branches/OaaS/HeuristicLab.Services.Optimization.Controller
- Files:
-
- 3 added
- 1 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OaaS/HeuristicLab.Services.Optimization.Controller/HL/HiveScenarioManager.cs
r8958 r9062 19 19 using Microsoft.WindowsAzure.StorageClient; 20 20 using HeuristicLab.Services.Optimization.ControllerService.Azure; 21 using System.Data; 21 22 22 23 namespace HeuristicLab.Services.Optimization.ControllerService { … … 112 113 var mapper = CompileMapper(mapperString); 113 114 114 /*@"using System; 115 using System.Collections.Generic; 116 using System.Linq; 117 using System.Text; 118 using HeuristicLab.Data; 119 using HeuristicLab.Services.Optimization.ControllerService.Model; 120 using HeuristicLab.Optimization; 121 using HeuristicLab.Services.Optimization.ControllerService; 122 using HeuristicLab.Algorithms.GeneticAlgorithm; 123 using HeuristicLab.Problems.TravelingSalesman; 124 public class TSPScenarioMapper : IScenarioMapper { 125 public void MapScenario(OptimizationScenario scenario, IAlgorithm algorithm) { 126 Console.WriteLine(""Mapping scenario!""); 127 var ga = algorithm as GeneticAlgorithm; 128 var problem = algorithm.Problem as TravelingSalesmanProblem; 129 130 problem.BestKnownQuality = HLMapper.ConvertToDoubleValue(scenario.InputParameters.FindByName(""BestKnownQuality"")); 131 problem.BestKnownSolution = HLMapper.ConvertToPermutation(scenario.InputParameters.FindByName(""BestKnownSolution"")); 132 problem.Coordinates = HLMapper.ConvertToDoubleMatrix(scenario.InputParameters.FindByName(""Coordinates"")); 133 var evalParam = HLMapper.GetStringValue(scenario.InputParameters.FindByName(""EvaluatorParameter"")); 134 if (evalParam == ""HeuristicLab.Problems.TravelingSalesman.TSPRoundedEuclideanPathEvaluator"") { 135 problem.EvaluatorParameter.Value = new TSPRoundedEuclideanPathEvaluator(); 136 } 137 else if (evalParam == ""HeuristicLab.Problems.TravelingSalesman.TSPGeoPathEvaluator"") { 138 problem.EvaluatorParameter.Value = new TSPGeoPathEvaluator(); 139 } 140 else { 141 problem.EvaluatorParameter.Value = new TSPEuclideanPathEvaluator(); 142 } 143 problem.UseDistanceMatrix = HLMapper.ConvertToBoolValue(scenario.InputParameters.FindByName(""UseDistanceMatrix"")); 144 Console.WriteLine(""Mapping algorithm...""); 145 ga.Mutator = HLMapper.FindInItemSet<HeuristicLab.Optimization.IManipulator>(ga.MutatorParameter.ValidValues, scenario.AlgorithmParameters.FindByName(""Mutator"")); 146 ga.CrossoverParameter.Value = HLMapper.FindOperator<HeuristicLab.Optimization.ICrossover>(problem, scenario.AlgorithmParameters.FindByName(""CrossoverParameter"")); 147 ga.Elites = HLMapper.ConvertToIntValue(scenario.AlgorithmParameters.FindByName(""Elites"")); 148 ga.MaximumGenerations = HLMapper.ConvertToIntValue(scenario.AlgorithmParameters.FindByName(""MaximumGenerations"")); 149 ga.MutationProbability = HLMapper.ConvertToPercentValue(scenario.AlgorithmParameters.FindByName(""MutationProbability"")); 150 ga.PopulationSize = HLMapper.ConvertToIntValue(scenario.AlgorithmParameters.FindByName(""PopulationSize"")); 151 ga.Seed = HLMapper.ConvertToIntValue(scenario.AlgorithmParameters.FindByName(""Seed"")); 152 ga.Selector = HLMapper.FindInItemSet<HeuristicLab.Optimization.ISelector>(ga.SelectorParameter.ValidValues, scenario.AlgorithmParameters.FindByName(""Selector"")); 153 ga.SetSeedRandomly = HLMapper.ConvertToBoolValue(scenario.AlgorithmParameters.FindByName(""SetSeedRandomly"")); 154 } 155 }"*/ 156 mappers[scenario.Name] = mapper; 157 return mapper; 115 mappers[scenario.Name] = mapper; 116 return mapper; 158 117 } // lock 159 118 } // if … … 202 161 var waitingJobs = job.JobCount - job.CalculatingCount - job.FinishedCount; 203 162 Model.JobState? state = null; 204 var jobTasks = HiveServiceLocator.Instance.CallHiveService<IEnumerable<HeuristicLab.Clients.Hive.LightweightTask>>(s => s.GetLightweightJobTasks(job.Id)); 163 if (job.CalculatingCount > 0) 164 state = JobState.Calculating; 165 else if (job.JobCount == job.FinishedCount) 166 state = JobState.Finished; 167 else 168 state = JobState.Waiting; 169 /*var jobTasks = HiveServiceLocator.Instance.CallHiveService<IEnumerable<HeuristicLab.Clients.Hive.LightweightTask>>(s => s.GetLightweightJobTasks(job.Id)); 205 170 206 171 foreach (var task in jobTasks) { … … 220 185 state = JobState.Waiting; 221 186 else 222 state = JobState.Finished; 223 } 224 return new Model.Job() { Id = job.Id.ToString(), Name = job.Name, Resource = job.ResourceNames, State = state.Value };187 state = JobState.Finished; 188 }*/ 189 return new Model.Job() { Id = job.Id.ToString(), Name = job.Name, Resource = job.ResourceNames, State = state.Value, DateCreated = job.DateCreated }; 225 190 } 226 191 … … 286 251 287 252 //TODO: We might need images / +++ 253 288 254 private Parameter MapHiveDataType(string name, IItem item) { 289 255 Parameter result = new Parameter(); 290 256 result.Type = ParameterType.String; 257 //TODO: How shall we handle dll specific datatypes? 258 //if (item is PathTSPTour) { 259 // var tour = item as PathTSPTour; 260 //} 261 //else 291 262 if (item is IStringConvertibleValue) { 292 263 var value = (item as IStringConvertibleValue).GetValue(); … … 297 268 var value2 = (item as IStringConvertibleValueTuple).Item2.GetValue(); 298 269 result.Value = new HeuristicLab.Services.Optimization.ControllerService.Model.StringValue() { Name = name, Value = "{" + value1 + ", " + value2 + "}" }; 270 } 271 else if (item is DoubleArray) { 272 var array = item as DoubleArray; 273 double[] arrayValue = new double[array.Length]; 274 for (int i = 0; i < arrayValue.Length; ++i) { 275 arrayValue[i] = array[i]; 276 } 277 result.Value = new HeuristicLab.Services.Optimization.ControllerService.Model.DecimalVector() { Name = name, Value = arrayValue }; 278 } 279 else if (item is DoubleMatrix) { 280 var matrix = item as DoubleMatrix; 281 double[][] matrixValue = new double[matrix.Rows][]; 282 for (int i = 0; i < matrixValue.Length; ++i) { 283 matrixValue[i] = new double[matrix.Columns]; 284 for (int j = 0; j < matrixValue[i].Length; ++j) { 285 matrixValue[i][j] = matrix[i, j]; 286 } 287 } 288 result.Value = new HeuristicLab.Services.Optimization.ControllerService.Model.DecimalMatrix() { Name = name, Value = matrixValue }; 299 289 } 300 290 else if (item is IStringConvertibleArray) { … … 303 293 if (array.Length == 0) { 304 294 sb.Append("[ ]"); 305 } else { 295 } 296 else { 306 297 sb.Append("["); 307 for (int i =0; i < array.Length - 1; i++) {308 sb.Append(array.GetValue(i)).Append(", "); 298 for (int i = 0; i < array.Length - 1; i++) { 299 sb.Append(array.GetValue(i)).Append(", "); 309 300 } 310 301 sb.Append(array.GetValue(array.Length - 1)); … … 314 305 result.Value = new HeuristicLab.Services.Optimization.ControllerService.Model.StringValue() { Name = name, Value = value }; 315 306 } 307 else if (item is HeuristicLab.Analysis.DataTable) { 308 var table = item as HeuristicLab.Analysis.DataTable; 309 string[] names = new string[table.Rows.Count]; 310 double[][] results = new double[table.Rows.Count][]; 311 for (int i = 0; i < table.Rows.Count; i++ ) { 312 var columns = table.Rows.ToList()[i]; 313 names[i] = columns.Name; 314 results[i] = new double[columns.Values.Count]; 315 for (int j=0; j < columns.Values.Count; j++) { 316 results[i][j] = columns.Values[j]; 317 } 318 } 319 result.Value = new HeuristicLab.Services.Optimization.ControllerService.Model.DecimalMatrix() { Name = name, Value = results, RowNames = names }; 320 } 316 321 else if (item is IStringConvertibleMatrix) { 317 322 StringBuilder sb = new StringBuilder(); 318 323 var matrix = item as IStringConvertibleMatrix; 324 319 325 if (matrix.Rows == 0 || matrix.Columns == 0) { 320 326 sb.Append("[ ]"); 321 327 } 322 328 else { 329 323 330 sb.Append("[ "); 324 331 for (int r = 0; r < matrix.Rows; r++) { 325 332 sb.Append("( "); 326 333 for (int c = 0; c < matrix.Columns - 1; c++) { 334 matrix.GetValue(r, c); 327 335 sb.Append(matrix.GetValue(r, c)).Append(", "); 328 336 } -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/HeuristicLab.Services.Optimization.ControllerService.csproj
r8958 r9062 38 38 <Reference Include="HeuristicLab.Algorithms.GeneticAlgorithm-3.3"> 39 39 <HintPath>..\bin\HeuristicLab.Algorithms.GeneticAlgorithm-3.3.dll</HintPath> 40 </Reference> 41 <Reference Include="HeuristicLab.Analysis-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 42 <SpecificVersion>False</SpecificVersion> 43 <HintPath>..\bin\HeuristicLab.Analysis-3.3.dll</HintPath> 40 44 </Reference> 41 45 <Reference Include="HeuristicLab.Clients.Hive-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> … … 156 160 <Compile Include="Interfaces\DAL.cs" /> 157 161 <Compile Include="Interfaces\IScenarioManager.cs" /> 158 <Compile Include=" Model\ControllerModel.cs" />162 <Compile Include="Interfaces\Model\ControllerModel.cs" /> 159 163 <Compile Include="PlaceholderControllerService.cs" /> 160 164 <Compile Include="Properties\AssemblyInfo.cs" /> … … 165 169 <WCFMetadata Include="Service References\" /> 166 170 </ItemGroup> 167 <ItemGroup /> 171 <ItemGroup> 172 <None Include="packages.config" /> 173 </ItemGroup> 168 174 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> 169 175 <PropertyGroup>
Note: See TracChangeset
for help on using the changeset viewer.