-
Notifications
You must be signed in to change notification settings - Fork 0
Decision Example
This example extends the example in Example document.
It builds the model that allows the computer system to calculate the best decision
between "Sending" or "Not Sending" the repair crew.
Some additional nodes were added to original Bayesian example:
- The Loss node defines the probabilities of customer loss depending on the severity of the
of the problem
(Damage), the customer making a Service Call, and whether a Repair Crew was dispatched to expedite the fixing of the problem - The "Decision Node" SendCrew defines the observation
(Sample)that the decision of whether or not to send a Repair Crew will be based on. These are Alert, Maintenance Schedule,
Packet Drop, and Service Call - The "Utility Node" Utility defines the "Costs and Benefits" of variables on the graph that affect the utility. In this example, those include revenue loss due to Customer Loss, the cost of Crew Dispatch, and the additional expense of Crew Dispatch due to bad Weather or concurrent Maintenance on the network
See [Example] (Example.md) for the bulk of graph initialization
db.AddVar("CustomerLoss"); // Customer loss probabilities
db.AddVar("SendCrew", VarType_Decision); // Decision variable
db.AddVar("Utility", VarType_Utility); // Utility node to track the expense of sending crew and the loss of dissatisfied customersNotice that the Decision Variable ("SendCrew") and Utility variable ("Utility") have
to be explicitly marked as such by using the second parameter in the AddVar() call
std::shared_ptr<Factor> fCustomerLoss = std::shared_ptr<Factor>(new Factor({ db["Call"], db["Damage"], db["SendCrew"], db["CustomerLoss"] }, db["CustomerLoss"]));
*fCustomerLoss << 0.999F << 0.995F << 0.97F << 0.7F << 0.999F << 0.998F << 0.997 << 0.985 << fin; std::shared_ptr<Factor> fSendCrew = std::shared_ptr<Factor>(new Factor({ db["Sched"], db["Alert"],db["Drop"], db["Call"], db["SendCrew"] }, db["SendCrew"]));
fSendCrew->SetFactorType(VarType_Decision);Notice that the Decision node has to be explicitly marked with SetFactorType().
Also, the Decision factor does not have probability values assigned to it.
VarSet vsUtility;
vsUtility << db["Weather"] << db["Maint"] << db["SendCrew"] << db["CustomerLoss"];
std::shared_ptr<Factor> fUtility = std::make_shared<Factor>(vsUtility, db["Utility"]);
*fUtility << 0. << 0. << 0. << 0. << -300. << -400. << -500. << -600. << -5000. << -5000. << -5000. << -5000. << -5300. << -5400. << -5500. << -5600.;
fUtility->SetFactorType(VarType_Utility);The values assigned to the Utility Factor are not probabilities but
Costs and Gains associated with Graph variables.
In this example, Costs/Losses are represented by negative values.
You will notice that values associated with all combinations where
CustomerLoss=FALSE and SendCrew=FALSE are 0, because there are no costs
due to Weather or Maintenance associated with this graph.
fs.AddFactor(fCustomerLoss);
fs.AddFactor(fSendCrew);
fs.AddFactor(fUtility); std::shared_ptr<DecisionBuilderHelper> dh = fs.BuildDecision();
As simple as that, the Library builds the full matrix of optimal decisions
contained in the DecisionBuilderHelper object
ClauseValue res1 = dh->GetDecisions(Clause({
{ db["Call"] , true },
{ db["Alert"] , true },
{ db["Sched"], false },
{ db["Drop"],false }
}));The ClauseValue result contains both the value of the decision variable
"SendCrew", as well as the statistically adjusted utility value associated
with this variable
res1[db["SendCrew"]]; // bool value to send or to not send a crew
res1.GetVal(); // Statistically adjusted utility valueThe Library supports graphs with multiple decision variables that can be applied sequentially. See Decision Test unit test for an example of this approach
Intro
Getting Started
Walkthroughs