zoukankan      html  css  js  c++  java
  • 贝叶斯网络 未学习前数据结构

    /**
    author: lx
    date 4.11 2011
    biref BN
    */

    #pragma once
    #include
    <string>
    #include
    <map>
    #include
    <vector>
    #include
    <iostream>
    using namespace std;

    typedef pair
    < char, float > inter;

    /* struct of node */
    struct nbnode
    {
    char name[20]; /* name */

    vector
    < inter > nodeprob; /* probility of each node */

    };

    void print_nbnode( struct nbnode* node )
    {
    cout
    << "name is " << node->name << endl;

    int i;
    for ( i = 0; i < (node->nodeprob).size(); i++ )
    {
    cout
    << (node->nodeprob)[i].first << " is " << (node->nodeprob)[i].second << endl;
    }
    }


    #include "rbnetwork.h"
    #include
    <stdlib.h>
    #include
    <string.h>
    #include
    <stdio.h>
    #include
    <iostream>
    #include
    <list>
    #include
    <algorithm>
    using namespace std;

    int main( void )
    {
    int n;
    list
    < struct nbnode* > listnode;

    cout
    << "请输入参数个数!" << endl;
    cin
    >> n;

    int i;
    for ( i = 0; i < n; i++ )
    {
    struct nbnode* node = ( struct nbnode* )malloc( sizeof(struct nbnode ) );
    switch( i )
    {
    case 0:
    {
    strcpy( node
    ->name, "a" );

    inter int1, int2;
    int1.first
    = 'f';
    int1.second
    = 0.4f;
    int2.first
    = 't';
    int2.second
    = 0.6f;

    (node
    ->nodeprob).push_back( int1 );
    (node
    ->nodeprob).push_back( int2 );
    listnode.push_back( node ); }
    break;

    case 1:
    {
    strcpy( node
    ->name, "b" );

    inter int1, int2;
    int1.first
    = 'f';
    int1.second
    = 0.5f;
    int2.first
    = 't';
    int2.second
    = 0.5f;

    (node
    ->nodeprob).push_back( int1 );
    (node
    ->nodeprob).push_back( int2 ); listnode.push_back( node );
    }
    break;

    case 2:
    {
    strcpy( node
    ->name, "c" );

    inter int1, int2;
    int1.first
    = 'f';
    int1.second
    = 0.3f;
    int2.first
    = 't';
    int2.second
    = 0.7f;

    (node
    ->nodeprob).push_back( int1 );
    (node
    ->nodeprob).push_back( int2 ); listnode.push_back( node );
    }
    break;

    case 3:
    {
    strcpy( node
    ->name, "d" );

    inter int1, int2;
    int1.first
    = 'f';
    int1.second
    = 0.1f;
    int2.first
    = 't';
    int2.second
    = 0.9f;

    (node
    ->nodeprob).push_back( int1 );
    (node
    ->nodeprob).push_back( int2 ); listnode.push_back( node );
    }
    break;


    default:
    break;
    }

    }
    for_each ( listnode.begin(), listnode.end(), print_nbnode );
    cout
    << endl;

    return 0;
    }

  • 相关阅读:
    linux进程间通信-共享内存
    where和having子句的区别
    多进程和多线程的区别(转载)
    android手机调试时不能打印Logcat日志信息
    来源不清,随笔
    转载
    C语言和Lua的交互
    python常用代码笔记
    python入门问题(windows7+python35+pycharm)
    常用matlab代码笔记
  • 原文地址:https://www.cnblogs.com/lxgeek/p/2012821.html
Copyright © 2011-2022 走看看