Solved

trying to figure out the logic for a karnaugh map in order to implement it to minimize a boolean expression please help!!

Posted on 2004-10-01
8
226 Views
Last Modified: 2010-03-31
I have created a karnaugh map into a gui that looks like the following

ab/cd  00   01   11   10
          ------------------------
00          0 | 0   | 0  |0
         ------------------------
01        0  |   0 |  0 |0
          -------------------------
11          0 |  0   |  0 |0
           ---------------------------
               0|   0  | 0  |0
10      ------------------------------

 All the 0's are Jbuttons and when a user clicks a button it turns into a 1 button
then i need to click a solve button and give the reduced boolean expression. So my logic needs to somehow group all the buttons into pairs.and then if there are larger pairs of two like pairs of four or eight use that pair because you need the most simplified map as possible.

So can anyone help me to figure out how i would go about doing this. I was thinking of since each button is an array of buttons .Example the top left corner is button[0],button[1],to the right of it etc......... So i'd somehow create a for vloop and say

for(inti = 0; i< 3 ;i++;)
{

  if (button[i].getText() && button[i+1].getText() == "1")
   then its a group of two so do something with it to remember but not sure what to do add it to a stack or something? because i need to check if its bigger than a pair and also if it's vertically a pair not just horizontilly.
}



please if anyone can help me get started i'd be forever in their debt!!
0
Comment
Question by:tyweed420
  • 4
  • 4
8 Comments
 
LVL 24

Expert Comment

by:sciuriware
ID: 12202241
I do not believe in eternal debts ....

What you need is:
1) a display : try a 5 x 5 gridbaglayout in which the 1st element is a place holder only.
Make the 8 buttons toggle buttons that control 8 boolean variables.
Make the 16 'infielders' JTextField's.
Setup a suitable Dimension (square?) that will be the preferred size and the maximum size of all
visible elements.
2) setup an actionlistener on every button, to be caught in one actionPerformed().
In there determine which button fired by comparing the action object against the buttons.
So put everything in ONE class.
3) firing buttons set or clear a boolean; from there conpute new contents of
associated JTextFields.

I think this is classwork, so I leave it to you to use colours instead on 1/0  values.

A Karnaugh map is widely used in education; you won't see it much in real-life
development, but I'm a devotede user.
If you know what it is used for you know that boolean expressions
can not just be delivered from any map setting.
It is up to the programmer to combine states into a smart expression.
It will be hard to do it in a program.
But that's your next step; try the above first.

;JOOP!
0
 

Author Comment

by:tyweed420
ID: 12204233
i'v got the buttons listening and the gui setup up fine i just don't know how to setup the algorithim to group the ones into the pairs . I just need a little idea what i could do to get me going some ideas psuedocode whatever! i'm stuck!
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12204591
Basicly you could see a 4(ABCD) x 4(abcd) map as:
boolean decision = (
      A && a || A && b || A && c || A && d
  || B && a || B && b  || B && c || B && d
  || C && a || C && b || C && c || C && d
  || D && a || D && b || D && c || D && d
                );
For easy cases you can simplify the expression into something like A || B || C && d
but do not expect that a program in this case can simplify everything.
Some complex situations simply can not. In such a case you have to produce the whole formula.

A Karnaugh map is to make visible what one can not understand from a formula.
It is NOT a panace!

;JOOP!
0
 

Author Comment

by:tyweed420
ID: 12204890
i'm confused how ABCD x abcd woild look?  ABCD  going horizontal and abcd vertical?

is this the idea?


ab/cd  00   01   11   10
          ------------------------
00          A a | B a | C a  | D a
         ------------------------
01         A b | B b   | C b | D b
          -------------------------
11          A  c |  B c  |  C c | D c
           ---------------------------
              A d|   B d  | C d  | D d
     ------------------------------
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:tyweed420
ID: 12205904
Just increased points to 300 please i'm willing to increase points to max or pay if i have to. I need to learn how to implement this algorithm . there is no way i'll learn just spinning my wheels like i'm doing ...........  help!
0
 
LVL 24

Accepted Solution

by:
sciuriware earned 300 total points
ID: 12206312
Sorry, your conditions are a, b, c ,d independently true(uppercase)  or false(lowercase) , so it should be:

ab/cd      cd     Cd      cD       CD

ab         abcd  abCd  abcD   abCD

Ab        Abcd  AbCd  AbcD  AbCD

... etc.

;JOOP!
0
 

Author Comment

by:tyweed420
ID: 12208764
ab/cd      cd     Cd      cD       CD

ab         abcd  abCd  abcD   abCD

Ab        Abcd  AbCd  AbcD  AbCD

aB       aBcd    aBCd  aBcD   aBCD

AB       ABcd    ABCd  ABcD   ABCD
                         ^
                       is this A || B ||C && d?     or does it mean look vertically through the entire first two rows because they are the ones with a small d hence && d?

ok here is the graph i'm trying like hell to figure out what to do with this sucker? ok lets say for edxample the statement you gave in an earlier statement
A || B ||C && d  does this mean look in the last row second column.Or does this statement  Forgive my ignorance i'm trying hard to understand how this will help to simplify the expressions
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12208929
Again, a Karnaugh map is a means to enable you to do smart grouping on boolean matrices.

ABCd stands for A && B && C && d

Now, the trick is to see if you can simplify the overall formula.
Example given: you should stop before a red sign and preferrably before a yellow sign,
but only if no police is around:

                     Red         Yellow        Green

no cop           stop          stop           go

cop               stop           stop          stop


simplifies to : drive if green and no cop.

It will be tough to do it with large maps!

;JOOP!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now