Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Need algorithm for generation of all variations of a 4x4 boolean table.

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    8
    My Mood
    Yeehaw
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Need algorithm for generation of all variations of a 4x4 boolean table.

    Hello everyone, I am currently try to solve a problem which requires the generation of all 2^16 tables and I'm afraid I have no clue how to do so efficiently. Could anyone please point me to an algorithm which could be utilized for such a task?

    Though I have no bugs at the moment I'll include the code so far anyway.

    public class logicp1
    {
      public static boolean[][][] tableGenerator( boolean[][] likeTable )
      {
     
      public static boolean checkRules(boolean[][] likeTable)
      { boolean isTrue = false;
     
          // Rule 1 Dana Likes Cody in terms of table values it is necessary that likeTable[3][0] is always true. Thus :
        System.out.println(" Passed rule 1 ");
        if ( likeTable[3][0] == false ) return false;
          // Rule 2 Bess does not Like Dana. Therfore likeTable[1][3] is always false. Thus :
        if ( likeTable[1][3] == true) return false;
         System.out.println(" Passed rule 2 ");
          // Rule 3 Cody does not like Abby, therefore likeTable[2][0] is always False
        if ( likeTable[2][0] == true ) return false;
         System.out.println(" Passed rule 3 ");
    // Rule 4 Nobody likes someone who does not like her. This translates to an if statement.
          // if likeTable[x][y] == true then likeTable[y][x] must be true
        for ( int i = 0; i < 4; i++)
        {
          for ( int c = 0; c < 4; c++)
          {
            if (likeTable[i][c] != likeTable[c][i]) return false;
          }
        }
         System.out.println(" Passed rule 4 ");
          // Rule 5 Dana like everyone who likes Bess . This means that if [x][1] == true, then likeTable[3][x] == true
        for ( int i = 0; i < 4; i++){
          if ( likeTable[i][1] == true && likeTable[3][i] == false ) return false;
        }
         System.out.println(" Passed rule 5 ");
     // Rule 6 Dana likes  everyone Bess likes. This can be ensured through a for loop which takes the values of Bess and 
          // replaced the values of Dana with them. e.g for i < 3; likeTable[3][i] gets likeTable[1][i] This also means that the dana array does not need to be manipulated during generation.
        for ( int i = 0; i < 4; i++){
          if (likeTable[1][i] == true && likeTable[3][i] == false ) return false;
        }
         System.out.println(" Passed rule 6 ");
        // Rule 7 Everybody likes somebody Meaning that for any likeTable[i][0-3] one of htese values must be true.
        for ( int i = 0; i < 4; i++)
        {
          for ( int c = 0; c < 4; c++)
          {
            if (likeTable[i][c] == true) isTrue = true;
          }
          if(!isTrue) return false;
        }
         System.out.println(" Passed rule 7 ");
        return true;
        }
     
      public static void printTable(boolean[][] likeTable)
      { String[] lines = new String[4];
        for ( int i = 0; i < 4; i++){
          for ( int c = 0; c < 4; c++){
            if ( likeTable[i][c] == true) lines[i] += " [x] ";
            else{ lines[i] += " [ ] "; }
          }
        }
     
       for ( int i = 0; i <4;i++)
       {
         System.out.println(lines[i]);}
      }
     
     
     
     
        public static void main (String[] args){
          boolean[][] likeTable = new boolean[4][4];
          // boolean table created, true = like, false = dislike
          /*  Abby Bess  Cody Dana
           *  Abby
           *  Bess
           *  Cody
           *  Dana
           /* Algorithm : I will load the rules of the world into the program and store them as constant rules. I will then generate variations of the truth table and test against the states
           * below is the initialization of each rule */
     
          System.out.println(likeTable[2][0]);
          likeTable[0][0] = true;
          likeTable[1][0] = true;
          likeTable[0][1] = true;
          likeTable[0][3] = true;
          likeTable[2][3] = true;
          likeTable[3][0] = true;
          likeTable[3][2] = true;
          printTable(likeTable);
          System.out.println(checkRules(likeTable));
          printTable(likeTable);
        // Rule 7 Everybody likes somebody. Meaning that for any likeTable[i][0-3] one of htese values must be true.
        }
    }
     // The algorithm will complete its task by going through each rule and fulfilling it by altering the values of the Table. It will however ruleCheck after each alteration to ensure that the world's adherence ot the rules is maintained.


  2. #2
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: Need algorithm for generation of all variations of a 4x4 boolean table.

    D...D.. Double POST!

    Stop being silly and stick to your original thread:
    http://www.javaprogrammingforums.com...ean-table.html

    No more posts are to commence here.
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Need algorithm for generation of all variations of a 4x4 boolean table.

    Please read the forum rules. Thread locked.

Similar Threads

  1. Need algorithm for generation of all variations of a 4x4 boolean table.
    By LittleGreenMidget in forum Java Theory & Questions
    Replies: 16
    Last Post: September 26th, 2012, 10:47 AM
  2. pdf generation
    By deependeroracle in forum File I/O & Other I/O Streams
    Replies: 5
    Last Post: July 22nd, 2012, 01:11 AM
  3. PDF generation
    By deependeroracle in forum JDBC & Databases
    Replies: 2
    Last Post: June 26th, 2012, 10:29 AM
  4. Okay Here Goes...World and Map Generation.
    By rooster5105 in forum Algorithms & Recursion
    Replies: 1
    Last Post: October 30th, 2011, 02:45 PM
  5. Boolean method returning a boolean value
    By Deprogrammer in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 21st, 2010, 10:56 AM