Below is an example Managed C++ (i.e., "C++/CLI") program that does the same thing as the "Demo" program that ships with Netica C-API. There is a Visual Studio project for it, called "Netica Demo for CLR C++" within the " Netica\Netica xxx\Programming Examples " folder of the Netica download package. (more info on programming Netica in Managed C++)
using namespace System;
using namespace Netica;
int main (array<String ^> ^args)
{
Console::WriteLine ("Welcome to Netica API for Managed C++ !"); |
|
Netica::Application^ app = gcnew Netica::Application; |
app->Visible = true; |
String^ net_file_name = AppDomain::CurrentDomain->BaseDirectory + "..\\ChestClinic.dne"; |
|
Streamer^ file = app->NewStream (net_file_name, nullptr); |
BNet^ net = app->ReadBNet (file, ""); |
net->Compile(); |
|
BNode^ TB = net->Nodes->Item ["Tuberculosis"]; |
double bel = TB->GetBelief ("present"); |
Console::WriteLine ("The probability of tuberculosis is " + bel); |
|
BNode^ XRay = net->Nodes->Item ["XRay"]; |
XRay->EnterFinding ("abnormal"); |
bel = TB->GetBelief ("present"); |
Console::WriteLine ("Given an abnormal X-Ray, the probability of tuberculosis is " + bel); |
|
net->Nodes->Item["Cancer"]->EnterFinding("present"); |
bel = TB->GetBelief ("present"); |
Console::WriteLine ("Given abnormal X-Ray, Asia visit, and lung cancer, the probability of TB is " + bel); |
|
net->Delete(); |
if (!app->UserControl) app->Quit(); |
|
Console::WriteLine ("Press <enter> to quit."); |
Console::ReadLine(); |
|
return 0; |
} |