/*
============================================================================
Name : dbrv.h
Author : Stephen Cannon
Version : 0.1
Copyright : Copyright 2011 Stephen Cannon
Description :
============================================================================
*
* This file is part of LikelihoodWeighting.
*
* LikelihoodWeighting is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* LikelihoodWeighting is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with LikelihoodWeighting. If not, see .
*
*/
#ifndef DBRV_H_
#define DBRV_H_
#include
#include
#include
#include
#include "DBConnector.h"
#ifdef __cplusplus
extern "C" {
#endif
enum {MAX_SQL_ID_SIZE = 65};
enum
{
ERR_TOO_MANY_PARENTS = -13,
ERR_INVALID_STATE_TYPE = -14,
ERR_NO_BIN_STATE_FOR_VALUE = -15
};
typedef struct __ParentTypePair__
{
const char *parent;
char enumeratedType;
SQLSMALLINT precision;
} ParentTypePair;
typedef enum __StateType__
{
STATE_VALUE,
STATE_RANGE,
STATE_ENUM
} StateType;
// TODO For enums at least, maybe an ID table and make enumValue a char *?
typedef struct __State__
{
StateType type;
union
{
char enumValue[MAX_SQL_ID_SIZE];
double scalarValue;
double rangeValue[2];
} value;
} State;
typedef struct __DBRV__
{
const char *modelName;
const char *nodeName;
char enumNode;
State *stateList;
size_t numStates;
ParamBinding paramBindings[64]; // No more than ~32 parents per node
size_t numParams;
double dOutValue;
char strOutValue[BUFFER_SIZE];
size_t lastFreq;
SQLINTEGER lastFreqID, outValueID;
ColBinding columnBindings[2];
char querySQL[LARGE_BUFFER_SIZE];
DBConnector super;
} DBRV;
typedef struct __Evidence__
{
DBRV *rv;
State *state;
} Evidence;
char dbrv__init(DBRV *self,
const char *modelName,
const char *nodename,
char enumNode,
State *stateList,
size_t numStates,
ParentTypePair *parentTypeMap,
size_t numParents,
const char *connectionString);
char dbrv__start(DBRV *self);
char __dbrv__prepareQuerySQL(DBRV *self, char enumNode, ParentTypePair *parentTypeMap, size_t numParents);
char __dbrv__setupParamBinding(DBRV *self, const char *parentName, ParentTypePair *parentType);
char __dbrv__setupColumnBinding(DBRV *self, char enumNode);
char dbrv__logP(DBRV *self, Evidence *ev, size_t numEvNodes, double *probs);
char dbrv__randomSample(DBRV *self, Evidence *ev, size_t numEvNodes, State *sample);
char dbrv__getState(DBRV *self, const State *valState, const State **binState, size_t *i);
char dbrv__getStateFromScalar(DBRV *self, double value, const State **binState, size_t *i);
char dbrv__getStateFromRange(DBRV *self, double low, double high, const State **binState, size_t *i);
char dbrv__getStateFromEnum(DBRV *self, const char value[MAX_SQL_ID_SIZE], const State **binState, size_t *i);
char dbrv__stop(DBRV *self);
char dbrv__del(DBRV *self);
char overwriteString(char *strDest, size_t numElements, const char *strSrc, size_t *offset);
#ifdef __cplusplus
}
#endif
#endif /* DBRV_H_ */