Click here to Skip to main content
15,887,746 members
Home / Discussions / Algorithms
   

Algorithms

 
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 
Hi Rob,

thanks, I'll look forward to studying your code tomorrow (GMT + 7 here).

Right now the prototype is coming along nicely, and here's what the current calling convention looks like for generating a 5 element matrix of boolean combinations
XML
List<string> ExcludedCases = new List<string> {"DCBAE", "!D!C!BAE", "DCB!A!E"};

List<string> t = PermutationsManager.MakeBigSwitch
(
    IsVerboseOutput: true,
    IsExcludesAsComments: true,
    PriorityStr: "DCBAE",
    ClassTitle: "Test5Params",
    Excludes: ExcludedCases
);


0. ExcludedCases List<string>: cases to be either skipped or written out as comments: here defined separately for debugging, but could just as well have been written 'in-line' as the last argument to 'MakeBigSwitch.

1. IsVerboseOutput bool: controls whether output is minimal or fully commented.

2. IsExcludesAsComments bool: controls whether excluded cases are written as comments or skipped.

3. PriorityStr string: contains the order in which to write out 'switch 'case statements.

4. ClassTitle string: will be written into the generated class

5. Excludes is the List<string> of excluded cases

Given the input above, the output now looks something like this (excerpt):
C#
// sample auto-generated output
using System;
using BigSwitch_0_0;

public static class Test5Params
{
    // Test 5 parameters DCBAE
    // CodeProject article or tip in progress 
    public static BigSwitchBoolIntString BigSwitch3(bool D, bool C, bool B, bool A, bool E)
    {
        // better way to do this: look-up table ? bit-shifting ?
        int intSelector = (D ? 0 : 16) + (C ? 0 : 8) + (B ? 0 : 4) + (A ? 0 : 2) + (E ? 0 : 1);

        // data class for results
        BigSwitchBoolIntString resultData = new BigSwitchBoolIntString();
        // assume fail
        resultData.IsSuccess = false;

        switch (intSelector)
        {
            // case 0:
                // test case: D AND C AND B AND A AND E : All Values True
                // Console.WriteLine("True in case: #0");
                // return resultData.SetValue(true, 0, "DCBAE : All Values True");
                // break;
            case 1:
                // test case:  NOT D AND C AND B AND A AND E
                // Console.WriteLine("True in case: #1");
                return resultData.SetValue(true, 1, "!DCBAE");
                break;

            // ... more cases ...

            case 31:
                // test case:  NOT D AND  NOT C AND  NOT B AND  NOT A AND  NOT E : All Values False
                // Console.WriteLine("True in case: #31");
                return resultData.SetValue(true, 31, "!D!C!B!A!E : All Values False");
                break;
            default:
                throw new BigSwitchFailException("Error In: Test5 parameters : DCBAE : DateTime: ");
        }
    }
}


The Type 'BigSwitchBoolIntString' is a helper class ... not shown here ... designed to 'package' the result of an evaluation. And 'BigSwitchFailException' ... not shown here ... is a custom Exception ... just in case demons strike.

In about another half-day, I should have all you see above fully implemented.

Appreciate any thoughts, ideas, you may have.

best, Bill
"In the River of Delights, Panic has not failed me." Jorge Luis Borges
modified on Friday, August 19, 2011 12:57 PM

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 
GeneralRe: connection routing algorithm for connecting rectangles with lines ? Pin
BillWoodruff5-Aug-11 7:29
professionalBillWoodruff5-Aug-11 7:29 
AnswerRe: connection routing algorithm for connecting rectangles with lines ? Pin
cjb1106-Aug-11 9:35
cjb1106-Aug-11 9:35 
GeneralRe: connection routing algorithm for connecting rectangles with lines ? Pin
BillWoodruff7-Aug-11 13:02
professionalBillWoodruff7-Aug-11 13:02 
AnswerRe: connection routing algorithm for connecting rectangles with lines ? Pin
Member 41945937-Aug-11 10:48
Member 41945937-Aug-11 10:48 
GeneralRe: connection routing algorithm for connecting rectangles with lines ? [modified] Pin
BillWoodruff7-Aug-11 14:30
professionalBillWoodruff7-Aug-11 14:30 
GeneralRe: connection routing algorithm for connecting rectangles with lines ? Pin
Member 41945937-Aug-11 15:34
Member 41945937-Aug-11 15:34 
GeneralRe: connection routing algorithm for connecting rectangles with lines ? Pin
Member 41945937-Aug-11 15:59
Member 41945937-Aug-11 15:59 
GeneralRe: connection routing algorithm for connecting rectangles with lines ? Pin
BillWoodruff7-Aug-11 17:40
professionalBillWoodruff7-Aug-11 17:40 
GeneralRe: connection routing algorithm for connecting rectangles with lines ? Pin
Member 41945938-Aug-11 17:57
Member 41945938-Aug-11 17:57 
GeneralRe: connection routing algorithm for connecting rectangles with lines ? Pin
BillWoodruff16-Aug-11 18:36
professionalBillWoodruff16-Aug-11 18:36 
QuestionRaytracing render quality [modified] Pin
Thomas.D Williams31-Jul-11 11:48
Thomas.D Williams31-Jul-11 11:48 
AnswerRe: Raytracing render quality Pin
Richard MacCutchan31-Jul-11 22:53
mveRichard MacCutchan31-Jul-11 22:53 

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.