コード例 #1
0
 internal OrangeConstraintRepeater(ConstraintNetwork constraintNetwork, OrangeModelSolverMap modelSolverMap, ModelModel theModel, OrangeValueMapper theValueMapper)
 {
     _constraintNetwork = constraintNetwork;
     _modelSolverMap    = modelSolverMap;
     _model             = theModel;
     _valueMapper       = theValueMapper;
     _arcBuilder        = new ArcBuilder(_modelSolverMap, _valueMapper);
 }
コード例 #2
0
 internal OrangeConstraintRepeater(ConstraintNetwork constraintNetwork, OrangeModelSolverMap modelSolverMap, BundleModel bundle, OrangeValueMapper theValueMapper)
 {
     _constraintNetwork = constraintNetwork;
     _modelSolverMap    = modelSolverMap;
     _bundle            = bundle;
     _valueMapper       = theValueMapper;
     _arcBuilder        = new ArcBuilder(_modelSolverMap, _valueMapper);
 }
コード例 #3
0
        /// <summary>
        /// Finds the clusters of nodes which should be in the same constraint network.
        /// This is based on the configuration constraints included in the branches.
        /// When only one branch has constraints each constraints generates its own cluster.
        /// Several clusters can be combined if they have duplicated node (which is not the StartOfTime)
        /// When several branches have constraints - the carthesian product (without duplicates) of the nodes in the constraints of the branches is generated, so even if the constraints do not use the same nodes they are all included in the same cluster.
        /// This is needed because there are satisfaction decision variables which depend on several nodes from different constraints.
        /// </summary>
        /// <returns></returns>
        public List <List <Node> > GetNodeClusters()
        {
            List <List <Node> > clusters = new List <List <Node> >();

            if (this.IsCombination)
            {
                List <List <Node> >[] branchClusters = new List <List <Node> > [this.ConstraintBranches.Count];
                List <List <Node> >[] nonEmptyBranchClusters;

                for (int i = 0; i < this.ConstraintBranches.Count; i++)
                {
                    branchClusters[i] = this.ConstraintBranches[i].GetNodeClusters();
                }

                nonEmptyBranchClusters = branchClusters.Where(x => x.Count > 0).ToArray();

                if (nonEmptyBranchClusters.Length == 1)
                {
                    clusters = nonEmptyBranchClusters[0];
                }
                else if (nonEmptyBranchClusters.Length > 1)
                {
                    List <Node> masterCluster = new List <Node>();

                    // When several branches are active then all nodes are added in the same cluster
                    // This is because the decision variables of the problem "span" over all nodes in this case
                    for (int i = 0; i < nonEmptyBranchClusters.Length; i++)
                    {
                        masterCluster.AddRange(nonEmptyBranchClusters[i].SelectMany(x => x));
                    }

                    clusters.Add(masterCluster);
                }
            }
            else
            {
                foreach (ConfigurationConstraint constraint in this.ConfigurationConstraints)
                {
                    List <Node> constraintNodes = constraint.GetIncludedNodes();
                    clusters.Add(constraintNodes);
                }
            }

            ConstraintNetwork.NormalizeClusters(clusters);
            return(clusters);
        }
コード例 #4
0
 internal SolutionData(ConstraintNetwork network)
 {
     this.Stopwatch     = new Stopwatch();
     this.Log           = new Log();
     this.SolvedNetwork = network;
 }
コード例 #5
0
 internal SolutionDataMetric(ConstraintNetwork network)
     : base(network)
 {
 }
コード例 #6
0
        /// <summary>
        /// Solves the current problem given the configuration and the domain constraints
        /// </summary>
        /// <param name="configuration">The configuration to be structured</param>
        /// <param name="constraintsSource">The source for the domain constraints</param>
        /// <returns>The best found configuration structure given the constraints</returns>
        public ConfigurationStructure Solve(GKOConfiguration configuration, DomainConstraintsSource constraintsSource)
        {
            ConfigurationStructure       structure = new ConfigurationStructure();
            List <GKOStructuringContext> metricStructuredComponents;
            List <GKOStructuringContext> qualitativeStructuredComponents;
            List <ConstraintNetwork>     problemNetworks = new List <ConstraintNetwork>();
            RelationFamily metricRelations = StructuralRelationsManager.MetricRelationsFamily;
            Stopwatch      totalTime       = new Stopwatch();
            Stopwatch      stopwatch       = new Stopwatch();

            if (!this.Options.TmsConfigured)
            {
                throw new NotSupportedException("The TMS has to be configured before a structuring operation!");
            }
            if (configuration == null)
            {
                throw new InvalidOperationException("The configuration must be set before the solving process can start!");
            }
            if (constraintsSource == null)
            {
                throw new InvalidOperationException("The domain constraints source must be set before the solving process can start!");
            }

            constraintsSource.LoadDomainConstraints();

            totalTime.Start();

            stopwatch.Start();
            GenerateConfigurationConstraints(configuration, constraintsSource);
            stopwatch.Stop();

            ProcessLog.AddItem(LogType.Info, String.Format("Generating configuration constraints finished ({0} ms)", stopwatch.ElapsedMilliseconds));

            // Finding all structured conmponents which include metric reasoning...
            metricStructuredComponents = configuration.StructuringContexts.Where(x => x.Active && x.IncludedRelationFamilies.Contains(metricRelations)).ToList();
            // ... and qualitative reasoning
            qualitativeStructuredComponents = configuration.StructuringContexts.Where(x => x.Active && x.IncludedRelationFamilies.Any(y => y != metricRelations)).ToList();

            // Generating the metric constraint networks
            if (metricStructuredComponents.Count != 0)
            {
                List <ConstraintNetwork> metricNetworks = new List <ConstraintNetwork>();

                ProcessLog.AddItem(LogType.Info, String.Format("Generating metric constraint networks out of composite components starting"));
                stopwatch.Restart();

                metricNetworks = ConstraintNetwork.GenerateMetricConstraintNetworks(metricStructuredComponents, this.tms, this.Options, this.ProcessLog);
                problemNetworks.AddRange(metricNetworks);

                stopwatch.Stop();
                ProcessLog.AddItem(LogType.Info, String.Format("{0} metric constraint networks generated out of {1} composite components ({2} ms)", metricNetworks.Count, metricStructuredComponents.Count, stopwatch.ElapsedMilliseconds));
            }

            // Generating the qualitative constraint networks
            if (qualitativeStructuredComponents.Count != 0)
            {
                ProcessLog.AddItem(LogType.Info, String.Format("Generating qualitative constraint networks for the composite components starting"));
                stopwatch.Restart();
                foreach (var strComponent in qualitativeStructuredComponents)
                {
                    // Generating a new constraint network foreach qualitative calculus in a StructuredComponent
                    foreach (var calculus in strComponent.IncludedRelationFamilies.Where(x => x != metricRelations))
                    {
                        problemNetworks.Add(ConstraintNetwork.GenerateQualitativeConstraintNetwork(strComponent, calculus, this.ProcessLog));
                    }
                }
                stopwatch.Stop();
                ProcessLog.AddItem(LogType.Info, String.Format("Generating qualitative constraint networks for the composite components finished ({0} ms)", stopwatch.ElapsedMilliseconds));
            }

            foreach (var network in problemNetworks)
            {
                ProcessLog.AddItem(LogType.Info, String.Format("Starting structuring of constraint network {0}", network.UId));
                stopwatch.Restart();

                structure.AddSolutionInformation(network.Solve(this.Options, tms));

                stopwatch.Stop();
                ProcessLog.AddItem(LogType.Info, String.Format("Structuring of constraint network {0} finished ({1} ms)", network.UId, stopwatch.ElapsedMilliseconds));
            }

            totalTime.Stop();
            ProcessLog.AddItem(LogType.Info, String.Format("Structuring configuration finished - {0} constraint networks processed ({1} ms)", problemNetworks.Count, totalTime.ElapsedMilliseconds));

            return(structure);
        }