#region License Information /* HeuristicLab * Copyright (C) 2002-2008 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.Collections.Generic; using System.Text; using System.Windows.Forms; using HeuristicLab.PluginInfrastructure; using System.Net; using System.ServiceModel; using HeuristicLab.CEDMA.DB.Interfaces; using HeuristicLab.CEDMA.DB; using System.ServiceModel.Description; using System.Linq; using HeuristicLab.CEDMA.Core; namespace HeuristicLab.CEDMA.Server { public class Dispatcher { private List dispatchQueue; public IList DispatchQueue { get { return dispatchQueue.AsReadOnly(); } } private IStore store; public Dispatcher(IStore store) { this.store = store; this.dispatchQueue = new List(); } private void FillDispatchQueue() { Dictionary> numberOfModelsOfTargetVariableOfDataSet = new Dictionary>(); IList datasetStatements = store.Select(new Statement(Ontology.AnyEntity, Ontology.PredicateInstanceOf, Ontology.TypeDataSet)); foreach (Statement datasetStatement in datasetStatements) { numberOfModelsOfTargetVariableOfDataSet.Add(datasetStatement.Subject, new Dictionary()); IList modelStatements = store.Select(new Statement(datasetStatement.Subject, Ontology.PredicateHasModel, Ontology.AnyEntity)); foreach (Statement modelStatement in modelStatements) { IList modelAttributeStatements = store.Select(new Statement((Entity)modelStatement.Property, Ontology.PredicateModelAttribute, Ontology.AnyEntity)); foreach (Statement modelAttrStatement in modelAttributeStatements) { var targetVariableStatements = store.Select(new Statement((Entity)modelAttrStatement.Property, Ontology.PredicateModelAttributeName, Ontology.AnyEntity)) .Where(t => (string)((Literal)t.Property).Value == "TargetVariable") .SelectMany(t => store.Select(new Statement((Entity)modelAttrStatement.Property, Ontology.PredicateModelAttributeValue, Ontology.AnyEntity))) .GroupBy(t => (int)((Literal)t.Property).Value); foreach (var targetVariable in targetVariableStatements) { numberOfModelsOfTargetVariableOfDataSet[datasetStatement.Subject].Add(targetVariable.Key, targetVariable.Count()); } } } } foreach(KeyValuePair> dataSetEntry in numberOfModelsOfTargetVariableOfDataSet) { DataSet dataSet = new DataSet(store, dataSetEntry.Key); foreach(int targetVariable in dataSet.Problem.AllowedTargetVariables) if (!dataSetEntry.Value.ContainsKey(targetVariable) || dataSetEntry.Value[targetVariable] < 10) { QueueJob(dataSet.Name + " - target variable: " + targetVariable); } } } private void QueueJob(string job) { dispatchQueue.Add(job); } private string GetNextJob() { if (dispatchQueue.Count == 0) FillDispatchQueue(); string next = dispatchQueue[0]; dispatchQueue.RemoveAt(0); return next; } internal void Start() { FillDispatchQueue(); } } }