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
219 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

743 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

10 Experts available now in Live!

Get 1:1 Help Now