Programmatically generate decision table in C #?

I have a situation where I need users to determine solutions based on the number of specified conditions. For example, my program should automatically generate a matrix, as shown below, that there are two conditions (IsMale and IsSmoker):

IsMale:   YES YES NO  NO
IsSmoker: YES NO  YES NO

And the definition is user-defined, so any of the following can be done:

IsMale:   YES YES NO  NO
IsSmoker: YES NO  YES NO
Decision: T   F   T   F

IsMale:   YES YES NO  NO
IsSmoker: YES NO  YES NO
Decision: F   F   F   F

IsMale:   YES YES NO  NO
IsSmoker: YES NO  YES NO
Decision: T   T   T   T

There can be only two states for each condition: True and False . Thus, the total number of combinations is calculated as follows:

there are no possible states (S) for power no from conditions (C)   S ^ C = total number of combinations

4 possibilities (2 ^ 2 = 4)

Condition A   T T F F
Condition B   T F T F

8 possibilities (2 ^ 3 = 8)

Condition A   T T T T F F F F
Condition B   T T F F T F T F
Condition C   T F T F T T F F

, .

: Guffa. .

4 possibilities (2^2=4)

index = 0, ( 0)

binary   8 4 2 1  Value

original 0 0 0 1  1
& 1      0 0 0 1  1 T

original 0 0 1 0  2
& 1      0 0 0 1  0 F

original 0 0 1 1  3
& 1      0 0 0 1  1 T

original 0 1 0 0  4
& 1      0 0 0 1  0 F

index = 1, ( 1)

binary   8 4 2 1  Value
original 0 0 0 1  1
shift    0 0 0 0  0
& 1      0 0 0 1  0 F

original 0 0 1 0  2
shift    0 0 0 1  1
& 1      0 0 0 1  1 T

original 0 0 1 1  3
shift    0 0 0 1  1
& 1      0 0 0 1  1 T

original 0 1 0 0  4
shift    0 0 1 0  2
& 1      0 0 0 1  0 F

< > :

Condition 1: TFTF
Condition 2: FTTF
+2
5

:

int conditions = 3;
for (int c = 0; c < conditions; c++) {
    Console.WriteLine(
       "Condition {0} : {1}",
       (char)('A' + c),
       new String(
          Enumerable.Range(0, (1 << conditions))
          .Select(n => "TF"[(n >> c) & 1])
          .ToArray()
       )
    );
}

, ?

+4

djna , .

, , (: , ), . , , 2 ^ n .

n , , 2 ^ n , .

- , 0 2 ^ n - 1, . - : ( n = 3):

0: 0 0 0
1: 0 0 1
2: 0 1 0
3: 0 1 1
4: 1 0 0
5: 1 0 1
6: 1 1 0
7: 1 1 1

, !

+2

, , . , :

if (A && B && C) {
     return X;
}
if (!A && B && C) {
     return Y;
}

, ! , ! ! , , .

:

State         1 2 3 4
Condition A   T T F F

?

0

-, - . , ?

Condition A   T T F F
Condition B   T F T F
Decision      T F F F

, . AND.

, " " - . ?

for (members of getListOfCombinedStates(n) )
    print theMember

getListOfCombinedStates(int howMany) {
    if (  n == 1 )
        return  list of possible States
    else {
        create empty resultlist
        for ( members of getListofCombinedStates(howMany -1) )
           for ( members of listOfStates ) 
               create new CombinedState by suffixing state, add to resultList

        return resultList
     }

, n = 2 getListOfCombinedStates (2), getListOfCombinedStates (1), {T, F}.

getListOfCombinedStates (2) {T, F} T F , {T, T} {T, F}, {F, T} {F, F}.

, , getListOfCombinedStates (3) getListOfCombinedStates (2) .

0

, , , , , :

, ; ( F 0 T 1), .

Condition A   0 0 0 0 1 1 1 1
Condition B   0 0 1 1 0 0 1 1
Condition C   0 1 0 1 0 1 0 1

;).

(, .)

0

All Articles