Advertisement
Guest User

Untitled

a guest
Aug 12th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.08 KB | None | 0 0
  1. package main;
  2.  
  3. import java.io.FileWriter;
  4. import java.io.IOException;
  5. import java.text.DecimalFormat;
  6. import java.util.Random;
  7.  
  8. import javax.sound.midi.SysexMessage;
  9. public class Main
  10. {
  11.     static int growth;
  12.     static double variables;
  13.     static int j=0,k=0;
  14.     static int i=0;
  15.     static int bar;
  16.     static String fname = "testbed";
  17.     static FileWriter writer;
  18.     static Random gen;
  19.     static DecimalFormat df = new DecimalFormat("#");
  20.     public static void main(String[] args) throws IOException
  21.     {
  22.         for(i = 1; i<26; i++)
  23.         {
  24.             gen = new Random();
  25.             writer = new FileWriter(fname + i);
  26.         /*open the file for writing, each time its open it should be overridden*/
  27.         growth = (int)Math.pow(2, i);
  28.         writer.write("p cnf 3 " + growth + "\n");
  29.                 /*looping to create the new clauses i.e. whitespace and a 0 keeping in mind that the growth is exponential*/
  30.                 for(j=0;j<growth;j++)
  31.                 {
  32.                 /*      this loop is for the placement of the variables*/
  33.                         for(k=0; k<3;k++)
  34.                         {
  35.                                 variables = gen.nextInt(growth);               
  36.                                 bar = gen.nextInt(2);
  37.                                 if(k==0)
  38.                                 {
  39.                                 if(bar == 1)
  40.                                 {
  41.                                 writer.write("" + df.format(variables) + " ");
  42.                                 }
  43.                                 else
  44.                                 {
  45.                                 writer.write("-" +df.format(variables) + " ");
  46.                                 }
  47.                                 }
  48.                                 else
  49.                                 {
  50.                                 if(bar==1)
  51.                                 {
  52.                                 writer.write(" " + df.format(variables)+ " ");
  53.                                 }
  54.                                 else
  55.                                 writer.write(" -" + df.format(variables)+ " ");
  56.                                 }
  57.                         }
  58.                         writer.write(" 0 c \n");
  59.                 }
  60.                writer.close();
  61.         }
  62.         System.out.println(i + "testbeds created");
  63.     }//main
  64. }//class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement