Exemplo n.º 1
0
        private static void smethod_1(object object_0, Formula formula_0, string string_0)
        {
            Match match;

            switch (smethod_2(string_0, out match))
            {
            case ((Enum16)0):
                formula_0.Add(string_0);
                return;

            case ((Enum16)1):
            {
                string  str     = match.Groups["FunctionName"].Value;
                Formula formula = new Formula();
                formula.Add(str).StartGroup();
                foreach (string str2 in match.Groups["Parameters"].Value.Split(new char[] { ',' }))
                {
                    smethod_1(object_0, formula, str2);
                }
                formula.EndGroup();
                formula_0.Add(formula);
                return;
            }

            case ((Enum16)2):
            case ((Enum16)3):
            {
                Range range = new Range(string_0);
                formula_0.Add(range);
                return;
            }
            }
        }
Exemplo n.º 2
0
        public Formula ReduceVertexCoverToSat(AdjacentMap pUndirectedGraph, int pMinVertexCount)
        {
            Dictionary <string, Variable> variables = new Dictionary <string, Variable>();

            foreach (var key in pUndirectedGraph.Keys)
            {
                for (int i = 1; i <= pMinVertexCount; i++)
                {
                    variables.Add($"{key}|{i}", new Variable($"{key}|{i}"));
                }
            }

            Console.WriteLine("Created Variables");
            foreach (var variable in variables)
            {
                Console.WriteLine(variable.Value.ToString());
            }

            var formula = new Formula();

            for (int i = 1; i <= pMinVertexCount; i++)
            {
                if (i > 1)
                {
                    formula.Add(_and);
                }

                var atMostOneList     = variables.Values.Where(v => v.Name.EndsWith($"|{i}")).ToList();
                var atMostOneFormular = AtMostOne(atMostOneList);
                formula.AddRange(atMostOneFormular);
            }

            List <string> processedEdges = new List <string>();

            foreach (var key in pUndirectedGraph.Keys)
            {
                foreach (var adjacent in pUndirectedGraph[key])
                {
                    if (!processedEdges.Contains($"{key}|{adjacent}") && !processedEdges.Contains($"{adjacent}|{key}"))
                    {
                        var atLeastOneList = new List <Variable>();

                        for (int i = 1; i <= pMinVertexCount; i++)
                        {
                            atLeastOneList.Add(variables[$"{key}|{i}"]);
                            atLeastOneList.Add(variables[$"{adjacent}|{i}"]);
                        }

                        var atleastOneFormular = AtLeastOne(atLeastOneList);
                        formula.Add(_and);
                        formula.Add(atleastOneFormular);

                        processedEdges.Add($"{key}|{adjacent}");
                    }
                }
            }

            return(formula);
        }
 protected override System.Linq.Expressions.Expression VisitParameter(ParameterExpression p)
 {
     foreach (var atom in p.Name.Select(ch => new CharAtom(ch, Formula.TextStyle)))
     {
         Formula.Add(atom);
     }
     return(base.VisitParameter(p));
 }
 protected override System.Linq.Expressions.Expression VisitConstant(ConstantExpression c)
 {
     foreach (var atom in c.ToString().Select(ch => new CharAtom(ch, Formula.TextStyle)))
     {
         Formula.Add(atom);
     }
     return(base.VisitConstant(c));
 }
    public IFormula Parse(string textRepresentation)
    {
        IList <IToken> tokenList = new List <IToken>()
        {
            EQUALIZE, ADD, SUBTRACT, DIVIDE, MULTIPLY, GROUPSTART, GROUPEND
        };
        IFormula formula        = new Formula();
        IToken   currentToken   = new Token(TokenType.IDENTIFIER, "");
        bool     equalizerFound = false;

        for (int i = 0, len = textRepresentation.Length; i < len; i++)
        {
            string item = textRepresentation[i].ToString();
            if (item == " ")
            {
                continue;
            }
            IToken selectedToken = (from t in tokenList where string.Equals(t.Text, item) select t).FirstOrDefault();
            if (selectedToken == null)
            {
                currentToken.Text += item;
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(currentToken.Text))
                {
                    // contains an identifier
                    formula.Add(currentToken, equalizerFound);
                }
                if (selectedToken.TokenType != TokenType.EQUALIZER)
                {
                    formula.Add(selectedToken, equalizerFound);
                }
                else
                {
                    equalizerFound = true;
                }
                currentToken = new Token(TokenType.IDENTIFIER, "");
            }
        }
        return(formula);
    }
        public static Formula ReduceTo3Sat(AdjacentMap pGraph, Dictionary <string, Variable> pVariableStore)
        {
            Formula formular = new Formula();

            foreach (string key in pGraph.Keys)
            {
                Variable currentVertex;
                if (!pVariableStore.ContainsKey(key))
                {
                    currentVertex = new Variable(key);
                    pVariableStore.Add(key, currentVertex);
                }
                else
                {
                    currentVertex = pVariableStore[key];
                }

                foreach (string adjazen in pGraph[key])
                {
                    Variable adjazenVertex;
                    if (!pVariableStore.ContainsKey(adjazen))
                    {
                        adjazenVertex = new Variable(adjazen);
                        pVariableStore.Add(adjazen, adjazenVertex);
                    }
                    else
                    {
                        adjazenVertex = pVariableStore[adjazen];
                    }

                    formular.Add(new Bracket()
                    {
                        Not, currentVertex, Or, Not, adjazenVertex
                    });
                    formular.Add(And);
                }
            }

            formular.RemoveAt(formular.Count - 1);

            return(formular);
        }
        public static Formula ReduceTo3Sat(AdjacentMap pGraph)
        {
            Dictionary <String, Variable> variableStore = new Dictionary <string, Variable>();
            Operator and = new Operator(Operator.Types.And);
            Operator or  = new Operator(Operator.Types.Or);
            Operator not = new Operator(Operator.Types.Not);

            var formula = new Formula();

            var isFirst = true;

            foreach (var node in pGraph.Keys)
            {
                Variable red;
                if (!variableStore.ContainsKey($"{node}|Red"))
                {
                    red = new Variable($"{node}|Red");
                    variableStore.Add($"{node}|Red", red);
                }
                else
                {
                    red = variableStore[$"{node}|Red"];
                }

                Variable blue;
                if (!variableStore.ContainsKey($"{node}|Blue"))
                {
                    blue = new Variable($"{node}|Blue");
                    variableStore.Add($"{node}|Blue", blue);
                }
                else
                {
                    blue = variableStore[$"{node}|Blue"];
                }

                Variable green;
                if (!variableStore.ContainsKey($"{node}|Green"))
                {
                    green = new Variable($"{node}|Green");
                    variableStore.Add($"{node}|Green", green);
                }
                else
                {
                    green = variableStore[$"{node}|Green"];
                }

                var nodeHasColor = new Bracket()
                {
                    red, or, blue, or, green
                };

                if (!isFirst)
                {
                    formula.Add(and);
                }
                else
                {
                    isFirst = false;
                }
                formula.Add(nodeHasColor);

                foreach (var adjazenzNode in pGraph[node])
                {
                    Variable adjazenRed;
                    if (!variableStore.ContainsKey($"{adjazenzNode}|Red"))
                    {
                        adjazenRed = new Variable($"{adjazenzNode}|Red");
                        variableStore.Add($"{adjazenzNode}|Red", adjazenRed);
                    }
                    else
                    {
                        adjazenRed = variableStore[$"{adjazenzNode}|Red"];
                    }

                    Variable adjazenBlue;
                    if (!variableStore.ContainsKey($"{adjazenzNode}|Blue"))
                    {
                        adjazenBlue = new Variable($"{adjazenzNode}|Blue");
                        variableStore.Add($"{adjazenzNode}|Blue", adjazenBlue);
                    }
                    else
                    {
                        adjazenBlue = variableStore[$"{adjazenzNode}|Blue"];
                    }

                    Variable adjazenGreen;
                    if (!variableStore.ContainsKey($"{adjazenzNode}|Green"))
                    {
                        adjazenGreen = new Variable($"{adjazenzNode}|Green");
                        variableStore.Add($"{adjazenzNode}|Green", adjazenGreen);
                    }
                    else
                    {
                        adjazenGreen = variableStore[$"{adjazenzNode}|Green"];
                    }

                    formula.Add(and);
                    formula.Add(new Bracket()
                    {
                        not, red, or, not, adjazenRed
                    });

                    formula.Add(and);
                    formula.Add(new Bracket()
                    {
                        not, blue, or, not, adjazenBlue
                    });

                    formula.Add(and);
                    formula.Add(new Bracket()
                    {
                        not, green, or, not, adjazenGreen
                    });
                }
            }

            return(formula);
        }