/*
 * SATGen.java
 *
 * Created on March 10, 2006, 4:08 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package cz.pcland.sat;

import java.util.*;
import cz.pcland.io.*;
/**
 *
 * @author petr
 */
public class SATGen {
    static Random rand = new Random();

    /**
     * Creates a new instance of SATGen
     */
    public SATGen() {
    }
    
  
    
    static int randomInt(int max){
        return Math.abs(rand.nextInt()%max);
    }
    
    
    public SATInstance generate(int vars, int clas){
        SATInstance sat = new SATInstance();
        sat.append("c\nc This file was generated by cnf formula generator \nc \np cnf " + vars + " " + clas + "\n");
        // System.out.println("generated in satgen appeneded");
        for(int ii=0; ii < clas; ii++) {
            for(int jj=0; jj < 3; jj++) {
                if (randomInt(2)==1){sat.append("-");}
                sat.append( (1+randomInt(vars)) + " " );
            }
            sat.append( "0" + "\n");
        }
        System.out.println("generated in pre parse");
     
        sat.parse();
        System.out.println(sat.getString());
        System.out.println("generated in satgen");
        return sat;
    }
    
}
