Click here to Skip to main content
15,889,116 members
Home / Discussions / Algorithms
   

Algorithms

 
GeneralRe: Classification with Self organizing map/Kohonen network Pin
SharpSim21-Aug-11 22:17
SharpSim21-Aug-11 22:17 
AnswerRe: Classification with Self organizing map/Kohonen network Pin
BobJanova18-Aug-11 23:22
BobJanova18-Aug-11 23:22 
AnswerRe: Classification with Self organizing map/Kohonen network Pin
DaveAuld19-Aug-11 8:04
professionalDaveAuld19-Aug-11 8:04 
GeneralRe: Classification with Self organizing map/Kohonen network Pin
SharpSim22-Aug-11 22:33
SharpSim22-Aug-11 22:33 
Questionoptimizing the set of possible boolean outcomes of evaluating multiple conditions ? [modified] Pin
BillWoodruff16-Aug-11 19:02
professionalBillWoodruff16-Aug-11 19:02 
GeneralRe: pruning the set of possible boolean outcomes of multiple variables ? Pin
David198716-Aug-11 20:00
David198716-Aug-11 20:00 
GeneralRe: pruning the set of possible boolean outcomes of multiple variables ? Pin
BillWoodruff17-Aug-11 14:50
professionalBillWoodruff17-Aug-11 14:50 
GeneralRe: pruning the set of possible boolean outcomes of multiple variables ? Pin
BillWoodruff17-Aug-11 21:46
professionalBillWoodruff17-Aug-11 21:46 
Hi David,

Nothing like writing out by hand an example of what you want, and testing it against all possible inputs, to make you aware of issues you'll face in generating it auto-magically ... WTF | :WTF:

Wish I had the IL skills to look at how the compiler renders this and evaluate for efficiency. Is falling through to the 'default case' of a switch statement exactly the same as skipping over an 'if clause that has a 'return inside it ? I'd guess so.

Some obvious refactoring 'cries out' to be done in the 'brute force' example included here: mmm ... dare I utter the forbidden name: 'G*T*' ?

Would you really want to have beasts like this at large in your applications:
C#
public static class NestedSwitch
{
    // four condition   test matrix
    public static string Test4(bool A, bool B, bool C, bool D)
    {
        int intSelectorA = A ? 8 : 0;
        int intSelectorB = B ? 4 : 0;
        int intSelectorC = C ? 2 : 0;
        int intSelectorD = D ? 1 : 0;

        switch (intSelectorA)
        {
            case 8: // A = true
                switch (intSelectorB)
                {
                    case 4: // B = true
                        switch (intSelectorC)
                        {
                            case 2: // C = true
                                switch (intSelectorD)
                                {
                                    case 1: // D = true
                                        return "ABCD";
                                    default: // D   =   false
                                        return "ABC!D";
                                }
                            default: // C   =   false
                                switch (intSelectorD)
                                {
                                    case 1: // D = true
                                        return "AB!CD";
                                    default: // D   =   false
                                        return "AB!C!D";
                                }
                        }

                    default: // B   =   false
                        switch (intSelectorC)
                        {
                            case 2: // C = true
                                switch (intSelectorD)
                                {
                                    case 1: // D = true
                                        return "A!BCD";
                                    default: // D   =   false
                                        return "A!BC!D";
                                }
                            default: // C   =   false
                                switch (intSelectorD)
                                {
                                    case 1: // D = true
                                        return "A!B!CD";
                                    default: // D   =   false
                                        return "A!B!C!D";
                                }
                        }
                }
            default: // A = false
                switch (intSelectorB)
                {
                    case 4: // B = true
                        switch (intSelectorC)
                        {
                            case 2: // C = true
                                switch (intSelectorD)
                                {
                                    case 1: // D = true
                                        return "!ABCD";
                                    default: // D   =   false
                                        return "!ABC!D";
                                }
                            default: // C   =   false
                                switch (intSelectorD)
                                {
                                    case 1: // D = true
                                        return "!AB!CD";
                                    default: // D   =   false
                                        return "!AB!C!D";
                                }
                        }

                    default: // B   =   false
                        switch (intSelectorC)
                        {
                            case 2: // C = true
                                switch (intSelectorD)
                                {
                                    case 1: // D = true
                                        return "!A!BCD";
                                    default: // D   =   false
                                        return "!A!BC!D";
                                }
                            default: // C   =   false
                                switch (intSelectorD)
                                {
                                    case 1: // D = true
                                        return "!A!B!CD";
                                    default: // D   =   false
                                        return "!A!B!C!D";
                                }
                        }
                }
        }
    }
}

"In the River of Delights, Panic has not failed me." Jorge Luis Borges

GeneralRe: pruning the set of possible boolean outcomes of multiple variables ? Pin
David198717-Aug-11 21:52
David198717-Aug-11 21:52 
GeneralRe: pruning the set of possible boolean outcomes of multiple variables ? Pin
BillWoodruff17-Aug-11 22:10
professionalBillWoodruff17-Aug-11 22:10 
GeneralRe: pruning the set of possible boolean outcomes of multiple variables ? Pin
David198717-Aug-11 22:19
David198717-Aug-11 22:19 
GeneralRe: pruning the set of possible boolean outcomes of multiple variables ? [modified] Pin
BillWoodruff24-Aug-11 20:55
professionalBillWoodruff24-Aug-11 20:55 
AnswerRe: optimizing the set of possible boolean outcomes of evaluating multiple conditions ? Pin
Luc Pattyn17-Aug-11 15:59
sitebuilderLuc Pattyn17-Aug-11 15:59 
GeneralRe: optimizing the set of possible boolean outcomes of evaluating multiple conditions ? Pin
BillWoodruff17-Aug-11 19:20
professionalBillWoodruff17-Aug-11 19:20 
Answerlink to usable c# sample of output of logic-matrix auto-generator for your review and comments Pin
BillWoodruff18-Aug-11 15:27
professionalBillWoodruff18-Aug-11 15:27 
AnswerRe: optimizing the set of possible boolean outcomes of evaluating multiple conditions ? [modified] Pin
RobCroll19-Aug-11 5:02
RobCroll19-Aug-11 5:02 
GeneralRe: optimizing the set of possible boolean outcomes of evaluating multiple conditions ? Pin
David198719-Aug-11 5:32
David198719-Aug-11 5:32 
GeneralRe: optimizing the set of possible boolean outcomes of evaluating multiple conditions ? Pin
RobCroll19-Aug-11 5:46
RobCroll19-Aug-11 5:46 
GeneralRe: optimizing the set of possible boolean outcomes of evaluating multiple conditions ? Pin
David198719-Aug-11 6:04
David198719-Aug-11 6:04 
GeneralRe: optimizing the set of possible boolean outcomes of evaluating multiple conditions ? [modified] Pin
BillWoodruff19-Aug-11 6:51
professionalBillWoodruff19-Aug-11 6:51 
AnswerRe: optimizing the set of possible boolean outcomes of evaluating multiple conditions ? Pin
GParkings3-Sep-11 5:57
GParkings3-Sep-11 5:57 
Questionconnection routing algorithm for connecting rectangles with lines ? Pin
BillWoodruff2-Aug-11 23:47
professionalBillWoodruff2-Aug-11 23:47 
GeneralRe: connection routing algorithm for connecting rectangles with lines ? Pin
David19875-Aug-11 1:21
David19875-Aug-11 1:21 
GeneralRe: connection routing algorithm for connecting rectangles with lines ? Pin
BillWoodruff5-Aug-11 2:10
professionalBillWoodruff5-Aug-11 2:10 
GeneralRe: connection routing algorithm for connecting rectangles with lines ? Pin
David19875-Aug-11 2:40
David19875-Aug-11 2:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.