Python中文网

一个关于 编程问题的解答网站.

有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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) 个答案