Esempio n. 1
0
        private void ConvertBucket(OrBucketTracker bucketTracker)
        {
            var bucket    = bucketTracker.Bucket;
            var bucketMap = bucketTracker.BucketMap;

            for (var i = 0; i < bucket.Size; i++)
            {
                var bundleMap = new OrBundleMap(bucket.Bundle);
                foreach (var singleton in bucket.Bundle.Singletons)
                {
                    var variableBand = VariableBandEvaluator.GetVariableBand(singleton);
                    _valueMapper.AddBucketDomainValue(bucket, variableBand);
                    var variableRange       = variableBand.GetRange();
                    var orToolsVariableName = CreateOrToolsVariableNameFrom(bucket, i, singleton);
                    var orVariable          = _solver.MakeIntVar(variableRange.Lower, variableRange.Upper, orToolsVariableName);
                    bundleMap.Add(singleton, orVariable);
                    _cache.AddVariable(orVariable);
                }

#if false
                foreach (var innerBucket in bucket.Bundle.Buckets)
                {
                    var innerBucketMap     = new OrBucketVariableMap(innerBucket, bucketMap);
                    var innerBucketTracker = new OrBucketTracker(bucket, innerBucketMap);
//                    ConvertBucket(innerBucketTracker);
                }
#endif

                bucketMap.Add(bundleMap);
            }
            _cache.AddBucket(bucket.Name, bucketMap);
        }
Esempio n. 2
0
 /// <summary>
 /// Convert all buckets into a representation understood by the solver.
 /// </summary>
 /// <param name="model">The model.</param>
 internal void ConvertBuckets(ModelModel model)
 {
     foreach (var bucket in model.Buckets)
     {
         bucket.PopulateInstances(null);
         var bucketMap     = new OrBucketVariableMap(bucket, null);
         var bucketTracker = new OrBucketTracker(bucket, bucketMap);
         ConvertBucket(bucketTracker);
     }
 }
Esempio n. 3
0
        private void ExtractBucketLabelFrom(SolutionCollector solutionCollector, OrBucketVariableMap bucketVariableMap)
        {
            var bundleLabels = new List <BundleLabelModel>();

            foreach (var bundleMap in bucketVariableMap.GetBundleMaps())
            {
                var variableLabels = new List <SingletonVariableLabelModel>();
                foreach (var variableMap in bundleMap.GetVariableMaps())
                {
                    var solverValue = solutionCollector.Value(0, variableMap.SolverVariable);
                    var modelValue  = ConvertSolverValueToModel(bucketVariableMap.Bucket, solverValue);
                    variableLabels.Add(new SingletonVariableLabelModel(variableMap.ModelVariable, new ValueModel(modelValue)));
                }
                bundleLabels.Add(new BundleLabelModel(bucketVariableMap.Bucket.Bundle, variableLabels));
            }

            var bucketLabel = new BucketLabelModel(bucketVariableMap.Bucket, bundleLabels);

            this.snapshot.AddBucketLabel(bucketLabel);
        }
Esempio n. 4
0
        private void ConvertBucket(BucketVariableModel bucket)
        {
            var bucketMap = new OrBucketVariableMap(bucket);

            for (var i = 0; i < bucket.Size; i++)
            {
                var bundleMap = new OrBundleMap(bucket.Bundle);
                foreach (var singleton in bucket.Bundle.Singletons)
                {
                    var variableBand = VariableBandEvaluator.GetVariableBand(singleton);
                    _valueMapper.AddBucketDomainValue(bucket, variableBand);
                    var variableRange       = variableBand.GetRange();
                    var orToolsVariableName = CreateOrToolsVariableNameFrom(bucket, i, singleton);
                    var orVariable          = _solver.MakeIntVar(variableRange.Lower, variableRange.Upper, orToolsVariableName);
                    bundleMap.Add(singleton, orVariable);
                    _cache.AddVariable(orVariable);
                }

                bucketMap.Add(bundleMap);
            }
            _cache.AddBucket(bucket.Name, bucketMap);
        }
Esempio n. 5
0
 internal OrBucketVariableMap(BucketVariableModel bucket, OrBucketVariableMap parent)
 {
     _bundleMaps = new List <OrBundleMap>();
     Bucket      = bucket;
     Parent      = parent;
 }
 internal OrBucketTracker(BucketVariableModel bucket, OrBucketVariableMap bucketMap)
 {
     _bundles  = new List <OrBundleMap>();
     Bucket    = bucket;
     BucketMap = bucketMap;
 }
 internal void AddBucket(string name, OrBucketVariableMap variableMap)
 {
     this.bucketMap.Add(name, variableMap);
 }