Пример #1
0
        public void ConvertDefaults(List <DefaultAssignment> defaults)
        {
            ProductModel pm = ModelWorkspace.CreateFromFile(pmxFile).ProductModel;
            var          pmProductModelStructure = pm.ProductModelStructure;

            foreach (var defaultAssignment in defaults)
            {
                //var characteristic = _parseUtils.FindSelectionCriteriaCharacteristic( defaultAssignment.HierarchyElement );
                //var precondition = _parseUtils.GeneratePrecondition( characteristic, defaultAssignment.HierarchyElement );

                var model   = defaultAssignment.Model;
                var coutry  = defaultAssignment.Country;
                var variant = defaultAssignment.Variant;

                var defaultModel = new LogicModel();
                defaultModel.AddRule("", "", ExprBld.IfThen(
                                         (ExprBld.Variables["Model"] == model)
                                         .And(ExprBld.Variables["coutry"] == coutry)
                                         .And(ExprBld.Variables["variant"] == variant),
                                         ExprBld.Variables[defaultAssignment.Assignment.Characteristic]) ==
                                     defaultAssignment.Assignment.Value);
                var compiler          = new Core.Compile.Compilation.Compiler(defaultModel);
                var defaultSolveData  = compiler.CompileNddSolve();
                var scopedDefaultData = new ScopedDefaultData(new[] { "model", "country", "variant" }, defaultSolveData);

                var packagedModelSerializer = new PackagedModelSerializer();
                var packagedModel           = packagedModelSerializer.LoadAsync(cameronPackage).Result.CopyAndInclude(scopedDefaultData);
                packagedModelSerializer.SaveAsync(cameronPackage,
                                                  new[] { packagedModel }).Wait();
            }
        }
Пример #2
0
        public LogicModel CreateDefaultModel(IGrouping <string, DefaultAssignment> defaultAssignmentGroup, string variableFullName, VariableCollection variables)
        {
            var defaultModel = new LogicModel("defaultModel", null, variables);

            foreach (var defaultAssignment in defaultAssignmentGroup)
            {
                if (!ValuesInDomain(defaultAssignment, variables, variableFullName))
                {
                    Log.Warn($"value not in domain: {COUNTRY_VARIABLE} = {defaultAssignment.Country}");
                    continue;
                }
                var defaultExpr = ExprBld.IfThen(
                    (ExprBld.Variables[MODEL_VARIABLE] == defaultAssignment.Model)
                    .And(ExprBld.Variables[COUNTRY_VARIABLE] == defaultAssignment.Country)
                    .And(ExprBld.Variables[VARIANT_VARIABLE] == defaultAssignment.Variant),
                    ExprBld.Variables[variableFullName] == defaultAssignment.Assignment.Value
                    );

                var ruleDescription =
                    $"{defaultAssignment.Model}.{defaultAssignment.Country}.{defaultAssignment.Variant}-{defaultAssignment.Assignment.Value}";
                Log.Trace($"Adding default {ruleDescription}");
                defaultModel.AddRule(ruleDescription, ruleDescription, defaultExpr);
            }
            return(defaultModel);
        }