为CNF生成数学逻辑

时间:2015-10-13 07:35:03

标签: java cnf

我正在尝试动态生成数学逻辑并将其传递给递归函数dfsCompute但我无法这样做。因为我想知道我应该传递什么,以便传递的值被视为数组并相应地进行评估。请在下面找到代码段:

import java.io.FileInputStream;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.Scanner;


    public class test {
            //static List<Boolean> x=new ArrayList<Boolean>();
            //static boolean[] x=new boolean[3]; 
            public static void main(String args[]) throws IOException
            {
                int n,m,sizec;
                int depth=0;
                int arrayLength;
                //ArrayList variablesList=new ArrayList();
                String logic="";
                Scanner reader = new Scanner(new FileInputStream(args[0]));
                ArrayList literalSize=new ArrayList();
                //ArrayList<Integer> in=new ArrayList<Integer>();
                int[] in=new int[100];
                int i=0;
                //read file and add the values to an array
                while (reader.hasNext()) {
                    int y=reader.nextInt();
                    in[i]=y;
                    i++;
                }
                arrayLength=in.length;
                n=in[0];
                m=in[1];
                sizec=in[2];

                //create array based on the number of variables
                boolean[] x=new boolean[n];

                long startTime = System.currentTimeMillis();
                dfsCompute(depth,n,x,in,sizec);
                long endTime   = System.currentTimeMillis();
                long totalTime = endTime - startTime;
                System.out.println("Run time is "+totalTime+" milliseconds");
            } 

            static void dfsCompute(int depth)
            {   
                if(depth==n)
                {
                    if(((!(x[0]) || x[1])) && (!(x[1]) || !(x[2]))  && ((!(x[0]) || x[2]))==true)// 
                            {
                                System.out.println("The solution is");
                                System.out.println("X[0]"+x[0]);
                                System.out.println("X[1]="+ x[1]);
                                System.out.println("X[2]="+ x[2]);
                                System.out.println("\n");

                            }
                    return;
                }

                x[depth]=true;
                dfsCompute(depth+1,n,x);
                x[depth]=false;
                dfsCompute(depth+1,n,x);
            }
    }
 The input is 
Line 1: 3 3 2
Line 2: -1 2
Line 3: -2 -3
Line 4: -1 3 
where Line 1: n m sizeC// where n is the number of variables, and m the number of clauses and sizeC the number of literals in the clauses
Line 2 to m+1: a list of sizeC positive and negative numbers in the range 1 to n. If the number is negative the literal is negated.  

For eg:(!x1 or x2) && (!x2 or !x3) && (!x1 or x3) 
The input file:
Line 1: 3 3 2
Line 2: -1 2
Line 3: -2 -3
Line 4: -1 3 

请让我知道如何动态生成逻辑并将其传递给递归函数并在if条件下检查相同。

0 个答案:

没有答案