Article
· Jan 12, 2016 9m read

DecisionTree

Is there someone that has developped a program in order to create a 
"decisiontree"? Depending The answer to a question leads to another question, and so on, 
and so on, and there is an option to return to another point in the decisiontree.

Best regards,

Simon.

p.s. I've already got something, but it's not workable. But to get an idea:

Global Data weergeven

 
 
1:  ^DECISIONTREE(0) = "Heeft betrekking op|vraag"
2:  ^DECISIONTREE(0,0) = "Schoonmaak|radio"
3:  ^DECISIONTREE(0,1) = "Lekkage|radio"
4:  ^DECISIONTREE(0,1,0) = "Betreft|vraag"
5:  ^DECISIONTREE(0,1,0,0) = "Sprinkler|radio"
6:  ^DECISIONTREE(0,1,0,0,0) = "Maak een keuze|vraag"
7:  ^DECISIONTREE(0,1,0,0,0,0) = "Leiding|radio"
8:  ^DECISIONTREE(0,1,0,0,0,0,0) = "Het lekt:|vraag|||"
9:  ^DECISIONTREE(0,1,0,0,0,0,0,0) = "Druppelgewijs|radio|"
10:  ^DECISIONTREE(0,1,0,0,0,0,0,0,0) = "Wat voor melding staat er op het display?|vraag|||"
11:  ^DECISIONTREE(0,1,0,0,0,0,0,0,0,0) = " |text|||Sprinklerinstallaties"
12:  ^DECISIONTREE(0,1,0,0,0,0,0,1) = "Stroomt|radio|||Sprinklerinstallaties"
13:  ^DECISIONTREE(0,1,0,0,0,1) = "Sprinklerkop|radio"
14:  ^DECISIONTREE(0,1,0,0,0,1,0) = "Het lekt:|vraag||"
15:  ^DECISIONTREE(0,1,0,0,0,1,0,0) = "Druppelgewijs|radio||Sprinklerinstallaties"
16:  ^DECISIONTREE(0,1,0,0,0,1,0,0,0) = "Kunt u het met behulp van een emmer tijdelijk opvangen?|vraag||"
17:  ^DECISIONTREE(0,1,0,0,0,1,0,0,0,0) = "Ja|radio|||Sprinklerinstallaties"
18:  ^DECISIONTREE(0,1,0,0,0,1,0,0,0,1) = "Nee|radio|||Sprinklerinstallaties"
19:  ^DECISIONTREE(0,1,0,0,0,1,0,1) = "Stroomt|radio|||Sprinklerinstallaties"
Etcetera
Discussion (4)0
Log in or sign up to continue

start() public {
  do init()

  set result=$$ask(0)
  write !!,"Result: ",result 
}
init() {
  kill ^DECISIONTREE
  set ^DECISIONTREE(0)="Smoker"
  set ^DECISIONTREE(0,"Yes")=1
  set ^DECISIONTREE(0,"No")=2

  #; Smoker -> Yes
  set ^DECISIONTREE(1)="Age"
  set ^DECISIONTREE(1,"<30")=3
  set ^DECISIONTREE(1,">30")=4

  #; Smoker -> No
  set ^DECISIONTREE(2)="Diet"
  set ^DECISIONTREE(2,"Good")=3
  set ^DECISIONTREE(2,"Poor")=4

  #; Smoker -> Yes|Age -> <30
  set ^DECISIONTREE(3)="Less risk"

  #; Smoker -> Yes|Age -> >30
  set ^DECISIONTREE(4)="More risk"

  #; Smoker -> No|Diet -> Good
  set ^DECISIONTREE(5)="Less risk"

  #; Smoker -> No|Diet -> Poor
  set ^DECISIONTREE(6)="More risk"
}
ask(id) {
  set text=(^DECISIONTREE(id))
  quit:$data(^DECISIONTREE(id))=1 text
  
  write !,text
  set answer=""
  for i=1:1 {
    set answer=$order(^DECISIONTREE(id,answer),1,nextId)
    quit:answer=""
    set answer(i)=nextId
    write !,$justify(i,3),") ",answer
  }
  set nextId=$$read(.answer)
  quit:nextId="" "" 
  quit $$ask(nextId)
}
read(&answers) {
  write !
  do {
    write $char(13),"Option? "
    read res#1
    quit:$zconvert(res,"L")="q"
  while (res="")||('$data(answers(res)))
  
  write !
  
  quit $get(answers(res))
}

 

USER>d start^tree()
 
Smoker
  1) No
  2) Yes
Option? 2
 
Age
  1) <30
  2) >30
Option? 1
 
 
Result: Less risk

Thanks! I'm running it in IE through Weblink, but I understand what you're doing.

But it need to be somewhat more flexible, because it can hold thousands of questions.

(I need to be able to change positions of the questions/answers for example, all that flexibility)

 

Best regards,

Simon

It is just a simple working example. But for reali life, it could be in some class. And flexible it will be with good UI, storage anyway for such task is quite simple. How well will be your UI, for organize that tree, so flexible it will be. Here is an example of complete UI, for creatingand running Decision trees. I think you could try to connect this project with Cache. And I think it is possible to find more web-libraries, which could help you.