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
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!!
Question by:tyweed420
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
LVL 24

Expert Comment

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.


Author Comment

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!
LVL 24

Expert Comment

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!

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users


Author Comment

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

Author Comment

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!
LVL 24

Accepted Solution

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.


Author Comment

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
LVL 24

Expert Comment

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!


Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

726 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