开发者

how to implement c# code/logic based on decision tree?

开发者 https://www.devze.com 2023-03-13 07:14 出处:网络
i have big decision tree with many Yes/No questions. i need implement some code with c# and go trough this tree and get unique id as return.

i have big decision tree with many Yes/No questions.

i need implement some code with c# and go trough this tree and get unique id as return.

if-> 1=true, A=true, C=true -> return 111;

if -> 1=true, A=true, C=false -> return 110;

how can i implem开发者_如何学编程ent such a logic without if else? my decision tree is much, much bigger as this sample and if/else are not good solution. i think to do it in 2 methods. first Get QuestionID, and second method will get Unique ID of answer based on questions. please help me with some code ideas..

decision tree:

how to implement c# code/logic based on decision tree?


if this tree is fixed you can set all alternatives in a decision table(somewhat like truth table) and save it in a dictionary then use this dictionary to return the corresponding outcome.

Dictionary["1,A"]=OutCome_1;
Dictionary["1,A,C,true"]=OutCome_2;
Dictionary["1,A,C,false"]=OutCome_3;

etc


You have to define a decision matrix. Your code will then look like: discriminant = decision_matrix( 1, A, B, C, 2 ) switch (discriminant ) { case outcome_1: ... break;

case outcome_2: ... break;

default: throw ... break; }

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号