Пример #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);
        }
        private DomainRange CreateRangeFrom(VariableModel variable)
        {
            var variableBand  = VariableBandEvaluator.GetVariableBand(variable);
            var variableRange = variableBand.GetRange();

            return(CreateRangeFrom(variableRange));
        }
        private IntVar ProcessVariable(VariableModel variable)
        {
            var variableBand  = VariableBandEvaluator.GetVariableBand(variable);
            var variableRange = variableBand.GetRange();
            var orVariable    = solver.MakeIntVar(variableRange.Lower, variableRange.Upper, variable.Name.Text);

            this.cache.AddVariable(orVariable);

            return(orVariable);
        }
 private void ConvertSingletonVariables(ModelModel theModel)
 {
     foreach (var variable in theModel.Singletons)
     {
         var variableBand = VariableBandEvaluator.GetVariableBand(variable);
         this.valueMapper.AddVariableDomainValue(variable, variableBand);
         var orVariable = ProcessVariable(variable);
         this.cache.AddSingleton(variable.Name.Text, new Tuple <SingletonVariableModel, IntVar>(variable, orVariable));
     }
 }
        private OrangeBundleMap ConvertBundle(BucketVariableModel bucket, int bucketCount)
        {
            var bundleMap = new OrangeBundleMap(bucket.Bundle);

            foreach (var singleton in bucket.Bundle.Singletons)
            {
                var variableBand = VariableBandEvaluator.GetVariableBand(singleton);
                _valueMapper.AddBucketDomainValue(bucket, variableBand);
                var solverVariableName = CreateVariableNameFrom(bucket, bucketCount, singleton);
                var variableRange      = variableBand.GetRange();
                var solverVariable     = new SolverVariable(solverVariableName, CreateRangeFrom(variableRange));
                bundleMap.Add(singleton, solverVariable);
            }

            return(bundleMap);
        }
 private void ConvertAggregateVariables(ModelModel theModel)
 {
     foreach (var aggregate in theModel.Aggregates)
     {
         var variableBand = VariableBandEvaluator.GetVariableBand(aggregate);
         this.valueMapper.AddVariableDomainValue(aggregate, variableBand);
         var variableRange    = variableBand.GetRange();
         var orVariableVector = this.solver.MakeIntVarArray(aggregate.AggregateCount,
                                                            variableRange.Lower,
                                                            variableRange.Upper,
                                                            aggregate.Name.Text);
         this.cache.AddAggregate(aggregate.Name.Text,
                                 new Tuple <AggregateVariableModel, IntVarVector>(aggregate, orVariableVector));
         foreach (var orVar in orVariableVector)
         {
             this.cache.AddVariable(orVar);
         }
     }
 }
        private void MapValues(ModelModel model)
        {
            foreach (var variable in model.Variables)
            {
                switch (variable)
                {
                case SingletonVariableModel singletonVariable:
                    var singletonVariableBand = VariableBandEvaluator.GetVariableBand(variable);
                    _valueMapper.AddVariableDomainValue(singletonVariable, singletonVariableBand);
                    break;

                case AggregateVariableModel aggregateVariable:
                    var aggregateVariableBand = VariableBandEvaluator.GetVariableBand(aggregateVariable);
                    _valueMapper.AddVariableDomainValue(aggregateVariable, aggregateVariableBand);
                    break;

                default:
                    throw new NotImplementedException();
                }
            }
        }
Пример #8
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);
        }