C Sharp Tutorial Code 3: Building an Influence Diagram

From DSL

Jump to: navigation, search
public void UpgradeToInfluenceDiagram() {
 try {
   Network net = new Network();
   net.ReadFile("tutorial_a.xdsl");
   
   // Creating node "Invest" and setting/adding outcomes:
   net.AddNode(Network.NodeType.List, "Invest");
   net.SetOutcomeId("Invest", 0, "Invest");
   net.SetOutcomeId("Invest", 1, "DoNotInvest");
   
   // Creating the value node "Gain":
   net.AddNode(Network.NodeType.Table, "Gain");
   
   // Adding an arc from "Invest" to "Gain":
   net.AddArc("Invest", "Gain");
   
   // Adding an arc from "Success" to "Gain":
   net.AddArc("Success", "Gain");
   
   // Filling in the utilities for the node "Gain". The utilities are:
   // U("Invest" = Invest, "Success" = Success) = 10000
   // U("Invest" = Invest, "Success" = Failure) = -5000
   // U("Invest" = DoNotInvest, "Success" = Success) = 500
   // U("Invest" = DoNotInvest, "Success" = Failure) = 500
   double[] aGainDef = {10000, -5000, 500, 500};
   net.SetNodeDefinition("Gain", aGainDef);
   
   net.WriteFile("tutorial_b.xdsl");
 }
 catch (SmileException e) {
   Console.WriteLine(e.Message);
 }
}
Personal tools