join cud packages

This commit is contained in:
Vítor Santos Costa
2015-06-19 01:00:18 +01:00
parent 5746edafaf
commit e8e33e405a
18 changed files with 23 additions and 23 deletions

View File

@@ -0,0 +1,345 @@
/******************************************************************************\
* *
* SimpleCUDD library (www.cs.kuleuven.be/~theo/tools/simplecudd.html) *
* SimpleCUDD was developed at Katholieke Universiteit Leuven(www.kuleuven.be) *
* *
* Copyright Katholieke Universiteit Leuven 2008 *
* *
* Author: Theofrastos Mantadelis *
* File: Example.c *
* *
********************************************************************************
* *
* Artistic License 2.0 *
* *
* Copyright (c) 2000-2006, The Perl Foundation. *
* *
* Everyone is permitted to copy and distribute verbatim copies of this license *
* document, but changing it is not allowed. *
* *
* Preamble *
* *
* This license establishes the terms under which a given free software Package *
* may be copied, modified, distributed, and/or redistributed. The intent is *
* that the Copyright Holder maintains some artistic control over the *
* development of that Package while still keeping the Package available as *
* open source and free software. *
* *
* You are always permitted to make arrangements wholly outside of this license *
* directly with the Copyright Holder of a given Package. If the terms of this *
* license do not permit the full use that you propose to make of the Package, *
* you should contact the Copyright Holder and seek a different licensing *
* arrangement. *
* Definitions *
* *
* "Copyright Holder" means the individual(s) or organization(s) named in the *
* copyright notice for the entire Package. *
* *
* "Contributor" means any party that has contributed code or other material to *
* the Package, in accordance with the Copyright Holder's procedures. *
* *
* "You" and "your" means any person who would like to copy, distribute, or *
* modify the Package. *
* *
* "Package" means the collection of files distributed by the Copyright Holder, *
* and derivatives of that collection and/or of those files. A given Package *
* may consist of either the Standard Version, or a Modified Version. *
* *
* "Distribute" means providing a copy of the Package or making it accessible *
* to anyone else, or in the case of a company or organization, to others *
* outside of your company or organization. *
* *
* "Distributor Fee" means any fee that you charge for Distributing this *
* Package or providing support for this Package to another party. It does not *
* mean licensing fees. *
* *
* "Standard Version" refers to the Package if it has not been modified, or has *
* been modified only in ways explicitly requested by the Copyright Holder. *
* *
* "Modified Version" means the Package, if it has been changed, and such *
* changes were not explicitly requested by the Copyright Holder. *
* *
* "Original License" means this Artistic License as Distributed with the *
* Standard Version of the Package, in its current version or as it may be *
* modified by The Perl Foundation in the future. *
* *
* "Source" form means the source code, documentation source, and configuration *
* files for the Package. *
* *
* "Compiled" form means the compiled bytecode, object code, binary, or any *
* other form resulting from mechanical transformation or translation of the *
* Source form. *
* Permission for Use and Modification Without Distribution *
* *
* (1) You are permitted to use the Standard Version and create and use *
* Modified Versions for any purpose without restriction, provided that you do *
* not Distribute the Modified Version. *
* Permissions for Redistribution of the Standard Version *
* *
* (2) You may Distribute verbatim copies of the Source form of the Standard *
* Version of this Package in any medium without restriction, either gratis or *
* for a Distributor Fee, provided that you duplicate all of the original *
* copyright notices and associated disclaimers. At your discretion, such *
* verbatim copies may or may not include a Compiled form of the Package. *
* *
* (3) You may apply any bug fixes, portability changes, and other *
* modifications made available from the Copyright Holder. The resulting *
* Package will still be considered the Standard Version, and as such will be *
* subject to the Original License. *
* Distribution of Modified Versions of the Package as Source *
* *
* (4) You may Distribute your Modified Version as Source (either gratis or for *
* a Distributor Fee, and with or without a Compiled form of the Modified *
* Version) provided that you clearly document how it differs from the Standard *
* Version, including, but not limited to, documenting any non-standard *
* features, executables, or modules, and provided that you do at least ONE of *
* the following: *
* *
* (a) make the Modified Version available to the Copyright Holder of the *
* Standard Version, under the Original License, so that the Copyright Holder *
* may include your modifications in the Standard Version. *
* (b) ensure that installation of your Modified Version does not prevent the *
* user installing or running the Standard Version. In addition, the Modified *
* Version must bear a name that is different from the name of the Standard *
* Version. *
* (c) allow anyone who receives a copy of the Modified Version to make the *
* Source form of the Modified Version available to others under *
* (i) the Original License or *
* (ii) a license that permits the licensee to freely copy, modify and *
* redistribute the Modified Version using the same licensing terms that apply *
* to the copy that the licensee received, and requires that the Source form of *
* the Modified Version, and of any works derived from it, be made freely *
* available in that license fees are prohibited but Distributor Fees are *
* allowed. *
* Distribution of Compiled Forms of the Standard Version or Modified Versions *
* without the Source *
* *
* (5) You may Distribute Compiled forms of the Standard Version without the *
* Source, provided that you include complete instructions on how to get the *
* Source of the Standard Version. Such instructions must be valid at the time *
* of your distribution. If these instructions, at any time while you are *
* carrying out such distribution, become invalid, you must provide new *
* instructions on demand or cease further distribution. If you provide valid *
* instructions or cease distribution within thirty days after you become aware *
* that the instructions are invalid, then you do not forfeit any of your *
* rights under this license. *
* *
* (6) You may Distribute a Modified Version in Compiled form without the *
* Source, provided that you comply with Section 4 with respect to the Source *
* of the Modified Version. *
* Aggregating or Linking the Package *
* *
* (7) You may aggregate the Package (either the Standard Version or Modified *
* Version) with other packages and Distribute the resulting aggregation *
* provided that you do not charge a licensing fee for the Package. Distributor *
* Fees are permitted, and licensing fees for other components in the *
* aggregation are permitted. The terms of this license apply to the use and *
* Distribution of the Standard or Modified Versions as included in the *
* aggregation. *
* *
* (8) You are permitted to link Modified and Standard Versions with other *
* works, to embed the Package in a larger work of your own, or to build *
* stand-alone binary or bytecode versions of applications that include the *
* Package, and Distribute the result without restriction, provided the result *
* does not expose a direct interface to the Package. *
* Items That are Not Considered Part of a Modified Version *
* *
* (9) Works (including, but not limited to, modules and scripts) that merely *
* extend or make use of the Package, do not, by themselves, cause the Package *
* to be a Modified Version. In addition, such works are not considered parts *
* of the Package itself, and are not subject to the terms of this license. *
* General Provisions *
* *
* (10) Any use, modification, and distribution of the Standard or Modified *
* Versions is governed by this Artistic License. By using, modifying or *
* distributing the Package, you accept this license. Do not use, modify, or *
* distribute the Package, if you do not accept this license. *
* *
* (11) If your Modified Version has been derived from a Modified Version made *
* by someone other than you, you are nevertheless required to ensure that your *
* Modified Version complies with the requirements of this license. *
* *
* (12) This license does not grant you the right to use any trademark, service *
* mark, tradename, or logo of the Copyright Holder. *
* *
* (13) This license includes the non-exclusive, worldwide, free-of-charge *
* patent license to make, have made, use, offer to sell, sell, import and *
* otherwise transfer the Package with respect to any patent claims licensable *
* by the Copyright Holder that are necessarily infringed by the Package. If *
* you institute patent litigation (including a cross-claim or counterclaim) *
* against any party alleging that the Package constitutes direct or *
* contributory patent infringement, then this Artistic License to you shall *
* terminate on the date that such litigation is filed. *
* *
* (14) Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER *
* AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE *
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR *
* NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. *
* UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE *
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN *
* ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF *
* SUCH DAMAGE. *
* *
* The End *
* *
\******************************************************************************/
#include "simplecudd.h"
typedef struct _extmanager {
DdManager *manager;
DdNode *t, *f;
hisqueue *his;
namedvars varmap;
} extmanager;
void DFS(extmanager MyManager, DdNode *Current);
int compexpand(extmanager MyManager, DdNode *Current, extmanager MyManager2, DdNode *Current2);
int bufstrcat(char *targetstr, int targetmem, const char *srcstr);
void getalltruepaths(extmanager MyManager, DdNode *Current, const char *startpath, const char *prevvar);
int main(int argc, char **arg) {
extmanager MyManager;
DdNode *bdd, **forest;
bddfileheader fileheader;
int code;
char yn;
code = -1;
if (argc != 2) {
fprintf(stderr, "\nUsage: %s [filename]\nGenerates and traverses a BDD from file\n", arg[0]);
fprintf(stderr, "\nUsage: %s -online\nGenerates and traverses a BDD online mode\n", arg[0]);
return code;
}
RAPIDLOADON;
if (strcmp("-online", arg[1]) == 0) {
MyManager.manager = simpleBDDinit(0);
MyManager.t = HIGH(MyManager.manager);
MyManager.f = LOW(MyManager.manager);
MyManager.varmap = InitNamedVars(1, 0);
bdd = OnlineGenerateBDD(MyManager.manager, &MyManager.varmap);
} else {
fileheader = ReadFileHeader(arg[1]);
switch(fileheader.filetype) {
case BDDFILE_SCRIPT:
MyManager.manager = simpleBDDinit(fileheader.varcnt);
MyManager.t = HIGH(MyManager.manager);
MyManager.f = LOW(MyManager.manager);
MyManager.varmap = InitNamedVars(fileheader.varcnt, fileheader.varstart);
if (fileheader.version > 1) {
forest = FileGenerateBDDForest(MyManager.manager, MyManager.varmap, fileheader);
bdd = forest[0];
} else {
forest = NULL;
bdd = FileGenerateBDD(MyManager.manager, MyManager.varmap, fileheader);
}
break;
case BDDFILE_NODEDUMP:
MyManager.manager = simpleBDDinit(fileheader.varcnt);
MyManager.t = HIGH(MyManager.manager);
MyManager.f = LOW(MyManager.manager);
MyManager.varmap = InitNamedVars(fileheader.varcnt, fileheader.varstart);
bdd = LoadNodeDump(MyManager.manager, MyManager.varmap, fileheader.inputfile);
break;
default:
fprintf(stderr, "Error: not a valid file format to load.\n");
return code;
break;
}
}
int nextbdd = 0;
while (bdd != NULL) {
printf("Do you want to load parameter values from testdata.txt [y]? "); yn = getchar(); getchar();
if (yn == 'y') {
printf("yo\n");
LoadVariableData(MyManager.varmap, "testdata.txt");
printf("yo\n");
char **a;
a = GetVariableOrder("testdata.txt", MyManager.varmap.varcnt);
int aa;
for (aa = 0; aa < MyManager.varmap.varcnt; aa++)
printf("%s\n", a[aa]);
ImposeOrder(MyManager.manager, MyManager.varmap, a);
}
code = 0;
MyManager.his = InitHistory(GetVarCount(MyManager.manager));
if (strcmp("-online", arg[1]) != 0) {
DFS(MyManager, bdd);
printf("Do you need an export [y]? "); yn = getchar(); getchar();
if (yn == 'y') simpleNamedBDDtoDot(MyManager.manager, MyManager.varmap, bdd, "SimpleCUDDExport.dot");
printf("Do you want a save [y]? "); yn = getchar(); getchar();
if (yn == 'y') SaveNodeDump(MyManager.manager, MyManager.varmap, bdd, "SimpleCUDDSave.sav");
printf("Do you want to see all true paths [y]? "); yn = getchar(); getchar();
if (yn == 'y') {
ReInitHistory(MyManager.his, GetVarCount(MyManager.manager));
getalltruepaths(MyManager, bdd, "", "");
}
} else {
onlinetraverse(MyManager.manager, MyManager.varmap, MyManager.his, bdd);
}
nextbdd++;
if (forest != NULL) bdd = forest[nextbdd]; else bdd = NULL;
}
if (MyManager.manager != NULL) KillBDD(MyManager.manager);
return code;
}
void DFS(extmanager MyManager, DdNode *Current) {
DdNode *h, *l;
hisnode *Found;
char *curnode;
curnode = GetNodeVarNameDisp(MyManager.manager, MyManager.varmap, Current);
if (GetIndex(Current) < MyManager.varmap.varcnt) {
printf("%s(%f,%i,%s)\n", curnode, MyManager.varmap.dvalue[GetIndex(Current)], MyManager.varmap.ivalue[GetIndex(Current)], (char *) MyManager.varmap.dynvalue[GetIndex(Current)]);
} else {
printf("%s\n", curnode);
}
if ((Current != MyManager.t) && (Current != MyManager.f) &&
((Found = GetNode(MyManager.his, MyManager.varmap.varstart, Current)) == NULL)) {
l = LowNodeOf(MyManager.manager, Current);
h = HighNodeOf(MyManager.manager, Current);
printf("l(%s)->", curnode);
DFS(MyManager, l);
printf("h(%s)->", curnode);
DFS(MyManager, h);
AddNode(MyManager.his, MyManager.varmap.varstart, Current, 0.0, 0, NULL);
}
}
void getalltruepaths(extmanager MyManager, DdNode *Current, const char *startpath, const char *prevvar) {
DdNode *h, *l;
char *curnode, *curpath;
int pathmaxsize = 1024;
curpath = (char *) malloc(sizeof(char) * pathmaxsize);
curpath[0] = '\0';
pathmaxsize = bufstrcat(curpath, pathmaxsize, startpath);
pathmaxsize = bufstrcat(curpath, pathmaxsize, prevvar);
pathmaxsize = bufstrcat(curpath, pathmaxsize, "*");
curnode = GetNodeVarNameDisp(MyManager.manager, MyManager.varmap, Current);
if (Current == MyManager.t) {
printf("%s\n", curpath);
} else if (Current != MyManager.f) {
h = HighNodeOf(MyManager.manager, Current);
if (h != MyManager.f) {
getalltruepaths(MyManager, h, curpath, curnode);
}
l = LowNodeOf(MyManager.manager, Current);
if (l != MyManager.f) {
pathmaxsize = bufstrcat(curpath, pathmaxsize, "~");
getalltruepaths(MyManager, l, curpath, curnode);
}
}
free(curpath);
}
int bufstrcat(char *targetstr, int targetmem, const char *srcstr) {
int strinc = strlen(srcstr), strsize = strlen(targetstr);
while ((strsize + strinc) > (targetmem - 1)) {
targetmem *= 2;
targetstr = (char *) realloc(targetstr, sizeof(char) * targetmem);
}
strcat(targetstr, srcstr);
return targetmem;
}

View File

@@ -0,0 +1,67 @@
#
# default base directory for YAP installation
# (EROOT for architecture-dependent files)
#
prefix = @prefix@
exec_prefix = @exec_prefix@
ROOTDIR = $(prefix)
EROOTDIR = @exec_prefix@
abs_top_builddir = @abs_top_builddir@
#
# where the binary should be
#
BINDIR = $(EROOTDIR)/bin
#
# where YAP should look for libraries
#
LIBDIR=@libdir@
YAPLIBDIR=@libdir@/Yap
#
# where YAP should look for architecture-independent Prolog libraries
#
SHAREDIR=$(ROOTDIR)/share
#
#
CC=@CC@
#
#
# You shouldn't need to change what follows.
#
INSTALL=@INSTALL@
INSTALL_DATA=@INSTALL_DATA@
INSTALL_PROGRAM=@INSTALL_PROGRAM@
SHELL=/bin/sh
RANLIB=@RANLIB@
srcdir=@srcdir@
SO=@SO@
#4.1VPATH=@srcdir@:@srcdir@/OPTYap
CWD=$(PWD)
#
DYNAMIC =
CFLAGS = @CFLAGS@ -D__ANSI_C__=1
INCLUDE = -I@abs_top_builddir@ @CUDD_CPPFLAGS@
LINKFLAGS = -lm
LINKLIBS = @CUDD_LIBS@
default: problogbdd_lfi
problogbdd_lfi: problogbdd_lfi.o simplecudd.o general.o problogmath.o pqueue.o allocate.o iqueue.o adterror.o allocate.o
@echo Making problogbdd_lfi...
@echo Copyright Katholieke Universiteit Leuven 2008
@echo Authors: T. Mantadelis, A. Kimmig, B. Gutmann, I. Thon, G. Van den Broeck
$(CC) problogbdd_lfi.o simplecudd.o general.o problogmath.o pqueue.o iqueue.o adterror.o allocate.o $(LINKLIBS) $(LINKFLAGS) -o problogbdd_lfi
%.o : $(srcdir)/%.c
$(CC) $(CFLAGS) $(INCLUDE) $(DYNAMIC) -c $<
clean:
rm -f *.o problogbdd_lfi
install: default
$(INSTALL_PROGRAM) problogbdd_lfi $(DESTDIR)$(BINDIR)
install-examples:
distclean: clean
rm -f Makefile

View File

@@ -0,0 +1,47 @@
/******************************************************************
**
** ADTERROR.C:
**
** ADT Error Handler
**
** This file is part of Apt Abstrct Data Types (ADT)
** Copyright (c) 1991 -- Apt Technologies
** All rights reserved
******************************************************************/
#include "adterror.h"
//#include "gprintf.h"
//PUBLIC
//#ifdef __ANSI_C__
void ADTError(char *name, ADTErrorCodes error, char *proc)
//#else
//void ADTError(name,error,proc)
//char *name;
//ADTErrorCodes error;
//char *proc;
//#endif
{
fprintf(stderr,"ADT Error: ");
fprintf(stderr," Module: %s\n",name);
fprintf(stderr," Procedure: %s\n",proc);
fprintf(stderr," Error Code: %u\n",error);
exit(1);
}
//PUBLIC
//#ifdef __ANSI_C__
void ADTWarning(char *name, ADTWarningCodes warning, char *proc)
//#else
//void ADTWarning(name,warning,proc)
//char *name;
//ADTWarningCodes warning;
//char *proc;
//#endif
{
fprintf(stderr,"ADT Warning: ");
fprintf(stderr," Module: %s\n",name);
fprintf(stderr," Procedure: %s\n",proc);
fprintf(stderr," Warning Code: %u\n",warning);
}

View File

@@ -0,0 +1,66 @@
/******************************************************************
**
** ADTERROR.H:
**
** ADT Error Handler
**
** This file is part of Apt Abstrct Data Types (ADT)
** Copyright (c) 1991 -- Apt Technologies
** All rights reserved
******************************************************************/
#ifndef ADTERROR_H
#define ADTERROR_H
//#include "cheaders.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* ADT Names */
#define ADT_AStack "Array Stack"
#define ADT_AStackIter "Array Stack Iterator"
#define ADT_Buffer "Buffer"
#define ADT_BufferIO "Buffered I/O"
#define ADT_Deque "Deque"
#define ADT_DequeIter "Deque Iterator"
#define ADT_HashTable "Hash Table"
#define ADT_HashTableIter "Hash Table Iterator"
#define ADT_Queue "Queue"
#define ADT_QueueIter "Queue Iterator"
#define ADT_Stack "Stack"
#define ADT_StackIter "Stack Iterator"
#define ADT_Table "AVL Table"
#define ADT_TableIter "AVL Table Iterator"
#define ADT_Tree "AVL Tree"
#define ADT_TreeIter "AVL Tree Iterator"
/* ADT Error Codes */
typedef enum _ADTErrorCodes {
E_Allocation,
E_NullQueue,
E_NullQueueIter,
E_Seek,
E_SeekOverflow,
E_SeekUnderflow,
/* Added HashTable errors 03/22/2005 pma */
E_NullHashTable,
E_NullHashTableIter,
/* Added AVLTable errors 04/04/2005 pma */
E_NullAVLTable,
E_NullAVLTableIter,
E_Undefined
} ADTErrorCodes;
typedef enum _ADTWarningCodes {
W_Undefined
} ADTWarningCodes;
/* ADT Error Handler */
void ADTError(char *name, ADTErrorCodes error, char *proc);
void ADTWarning(char *name, ADTWarningCodes warning, char *proc);
#endif

View File

@@ -0,0 +1,59 @@
/******************************************************************
**
** ALLOCATE.C:
**
** Allocation Routines
**
** This file is part of Apt Computing Tools (ACT)
** Copyright (c) 1991 -- Apt Technologies
** All rights reserved
**
******************************************************************/
/* ---------- C Headers */
//#include "cheaders.h"
/* ---------- Headers */
#include "apt.h"
#include "allocate.h"
/* ---------- Private Globals */
PRIVATE int bytesAllocated = 0;
/* ---------- Functions */
/*
**
** Allocate
**
*/
PUBLIC
#ifdef __ANSI_C__
void *Allocate(int bytes)
#else
void *Allocate(bytes)
int bytes;
#endif
{
bytesAllocated += bytes;
return (void *)calloc(1,bytes);
}
/*
**
** Free
**
*/
PUBLIC
#ifdef __ANSI_C__
void Free(void *memory)
#else
void Free(memory)
void *memory;
#endif
{
free(memory);
}

View File

@@ -0,0 +1,30 @@
/******************************************************************
**
** ALLOCATE.H:
**
** Allocation Routines
**
** This file is part of Apt Computing Tools (ACT)
** Copyright (c) 1991 -- Apt Technologies
** All rights reserved
**
******************************************************************/
#ifndef ALLOCATE_H
#define ALLOCATE_H
/* ----------- Headers */
#include "apt.h"
/* ----------- Exported Function Prototypes */
#ifdef __ANSI_C__
void *Allocate(int);
void Free(void*);
#else
void *Allocate();
void Free();
#endif /* __ANSI_C__ */
#endif /* ALLOCATE_H */

View File

@@ -0,0 +1,70 @@
/******************************************************************
**
** APT.H:
**
** Definitions and Types for all APT modules
**
** This file is part of Apt Computing Tools (ACT)
** Copyright (c) 1991 -- Apt Technologies
** All rights reserved
**
******************************************************************/
#ifndef APT_H
#define APT_H
#include <stdlib.h>
/* ---------- Defines */
#ifndef ERROR
#define ERROR -1
#endif
#ifndef EXTERN
#define EXTERN extern
#endif
#ifndef FAILURE
#define FAILURE -1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifndef INFINITY
#define INFINITY 32768L
#endif
#ifndef PRIVATE
#define PRIVATE static
#endif
#ifndef PUBLIC
#define PUBLIC
#endif
#ifndef SUCCESS
#define SUCCESS 1
#endif
#ifndef TRUE
#define TRUE 1
#endif
/* ---------- Types */
#ifndef __ANSI_C__
#define __ANSI_C__
#endif
typedef void (*ApplyFunction)(void*);
typedef void (*ApplyFunction1)(void*,void*);
typedef void (*ApplyFunction2)(void*,void*,void*);
typedef void (*ApplyFunction3)(void*,void*,void*,void*);
typedef int (*ComparisonFunction)(void*, void*);
typedef void (*DisposeFunction)(void*);
typedef void (*ApplyFunctionGeneric)(void* target, void* args[]);
#endif /* APT_H */

View File

@@ -0,0 +1,50 @@
/*
* cheaders.h : A unified headers file for APT. It does slow down compile
* time somewhat, but this allows us to ensure consistent usage
* of header files and replace missing ones easily.
*/
#ifndef APT_CHEADERS_H
#define APT_CHEADERS_H
#include "apt_config.h"
#ifdef HAVE_CTYPE_H
#include <ctype.h>
#else
#error Your C compiler is very old (ctype.h missing). Time to upgrade. Sorry
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#else
#error Your C compiler is very old (string.h missing). Time to upgrade. Sorry
#endif
#ifdef HAVE_STDIO_H
#include <stdio.h>
#else
#error Your C compiler is very old (stdio.h missing). Time to upgrade. Sorry
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#else
#error Your C compiler is not ANSI C (stdlib.h missing). Time to upgrade. Sorry
#endif
#if HAVE_STDARG_H
# include <stdarg.h>
# define VA_START(a, f) va_start(a, f)
#else
# if HAVE_VARARGS_H
# include <varargs.h>
# define VA_START(a, f) va_start(a)
# endif
#endif
#ifndef VA_START
#error Your C compiler has no support for variable argument functions. Time to upgrade. Sorry.
#endif
#endif

View File

@@ -0,0 +1,277 @@
/******************************************************************************\
* *
* SimpleCUDD library (www.cs.kuleuven.be/~theo/tools/simplecudd.html) *
* SimpleCUDD was developed at Katholieke Universiteit Leuven(www.kuleuven.be) *
* *
* Copyright Katholieke Universiteit Leuven 2008 *
* *
* Author: Theofrastos Mantadelis *
* File: general.c *
* *
********************************************************************************
* *
* Artistic License 2.0 *
* *
* Copyright (c) 2000-2006, The Perl Foundation. *
* *
* Everyone is permitted to copy and distribute verbatim copies of this license *
* document, but changing it is not allowed. *
* *
* Preamble *
* *
* This license establishes the terms under which a given free software Package *
* may be copied, modified, distributed, and/or redistributed. The intent is *
* that the Copyright Holder maintains some artistic control over the *
* development of that Package while still keeping the Package available as *
* open source and free software. *
* *
* You are always permitted to make arrangements wholly outside of this license *
* directly with the Copyright Holder of a given Package. If the terms of this *
* license do not permit the full use that you propose to make of the Package, *
* you should contact the Copyright Holder and seek a different licensing *
* arrangement. *
* Definitions *
* *
* "Copyright Holder" means the individual(s) or organization(s) named in the *
* copyright notice for the entire Package. *
* *
* "Contributor" means any party that has contributed code or other material to *
* the Package, in accordance with the Copyright Holder's procedures. *
* *
* "You" and "your" means any person who would like to copy, distribute, or *
* modify the Package. *
* *
* "Package" means the collection of files distributed by the Copyright Holder, *
* and derivatives of that collection and/or of those files. A given Package *
* may consist of either the Standard Version, or a Modified Version. *
* *
* "Distribute" means providing a copy of the Package or making it accessible *
* to anyone else, or in the case of a company or organization, to others *
* outside of your company or organization. *
* *
* "Distributor Fee" means any fee that you charge for Distributing this *
* Package or providing support for this Package to another party. It does not *
* mean licensing fees. *
* *
* "Standard Version" refers to the Package if it has not been modified, or has *
* been modified only in ways explicitly requested by the Copyright Holder. *
* *
* "Modified Version" means the Package, if it has been changed, and such *
* changes were not explicitly requested by the Copyright Holder. *
* *
* "Original License" means this Artistic License as Distributed with the *
* Standard Version of the Package, in its current version or as it may be *
* modified by The Perl Foundation in the future. *
* *
* "Source" form means the source code, documentation source, and configuration *
* files for the Package. *
* *
* "Compiled" form means the compiled bytecode, object code, binary, or any *
* other form resulting from mechanical transformation or translation of the *
* Source form. *
* Permission for Use and Modification Without Distribution *
* *
* (1) You are permitted to use the Standard Version and create and use *
* Modified Versions for any purpose without restriction, provided that you do *
* not Distribute the Modified Version. *
* Permissions for Redistribution of the Standard Version *
* *
* (2) You may Distribute verbatim copies of the Source form of the Standard *
* Version of this Package in any medium without restriction, either gratis or *
* for a Distributor Fee, provided that you duplicate all of the original *
* copyright notices and associated disclaimers. At your discretion, such *
* verbatim copies may or may not include a Compiled form of the Package. *
* *
* (3) You may apply any bug fixes, portability changes, and other *
* modifications made available from the Copyright Holder. The resulting *
* Package will still be considered the Standard Version, and as such will be *
* subject to the Original License. *
* Distribution of Modified Versions of the Package as Source *
* *
* (4) You may Distribute your Modified Version as Source (either gratis or for *
* a Distributor Fee, and with or without a Compiled form of the Modified *
* Version) provided that you clearly document how it differs from the Standard *
* Version, including, but not limited to, documenting any non-standard *
* features, executables, or modules, and provided that you do at least ONE of *
* the following: *
* *
* (a) make the Modified Version available to the Copyright Holder of the *
* Standard Version, under the Original License, so that the Copyright Holder *
* may include your modifications in the Standard Version. *
* (b) ensure that installation of your Modified Version does not prevent the *
* user installing or running the Standard Version. In addition, the Modified *
* Version must bear a name that is different from the name of the Standard *
* Version. *
* (c) allow anyone who receives a copy of the Modified Version to make the *
* Source form of the Modified Version available to others under *
* (i) the Original License or *
* (ii) a license that permits the licensee to freely copy, modify and *
* redistribute the Modified Version using the same licensing terms that apply *
* to the copy that the licensee received, and requires that the Source form of *
* the Modified Version, and of any works derived from it, be made freely *
* available in that license fees are prohibited but Distributor Fees are *
* allowed. *
* Distribution of Compiled Forms of the Standard Version or Modified Versions *
* without the Source *
* *
* (5) You may Distribute Compiled forms of the Standard Version without the *
* Source, provided that you include complete instructions on how to get the *
* Source of the Standard Version. Such instructions must be valid at the time *
* of your distribution. If these instructions, at any time while you are *
* carrying out such distribution, become invalid, you must provide new *
* instructions on demand or cease further distribution. If you provide valid *
* instructions or cease distribution within thirty days after you become aware *
* that the instructions are invalid, then you do not forfeit any of your *
* rights under this license. *
* *
* (6) You may Distribute a Modified Version in Compiled form without the *
* Source, provided that you comply with Section 4 with respect to the Source *
* of the Modified Version. *
* Aggregating or Linking the Package *
* *
* (7) You may aggregate the Package (either the Standard Version or Modified *
* Version) with other packages and Distribute the resulting aggregation *
* provided that you do not charge a licensing fee for the Package. Distributor *
* Fees are permitted, and licensing fees for other components in the *
* aggregation are permitted. The terms of this license apply to the use and *
* Distribution of the Standard or Modified Versions as included in the *
* aggregation. *
* *
* (8) You are permitted to link Modified and Standard Versions with other *
* works, to embed the Package in a larger work of your own, or to build *
* stand-alone binary or bytecode versions of applications that include the *
* Package, and Distribute the result without restriction, provided the result *
* does not expose a direct interface to the Package. *
* Items That are Not Considered Part of a Modified Version *
* *
* (9) Works (including, but not limited to, modules and scripts) that merely *
* extend or make use of the Package, do not, by themselves, cause the Package *
* to be a Modified Version. In addition, such works are not considered parts *
* of the Package itself, and are not subject to the terms of this license. *
* General Provisions *
* *
* (10) Any use, modification, and distribution of the Standard or Modified *
* Versions is governed by this Artistic License. By using, modifying or *
* distributing the Package, you accept this license. Do not use, modify, or *
* distribute the Package, if you do not accept this license. *
* *
* (11) If your Modified Version has been derived from a Modified Version made *
* by someone other than you, you are nevertheless required to ensure that your *
* Modified Version complies with the requirements of this license. *
* *
* (12) This license does not grant you the right to use any trademark, service *
* mark, tradename, or logo of the Copyright Holder. *
* *
* (13) This license includes the non-exclusive, worldwide, free-of-charge *
* patent license to make, have made, use, offer to sell, sell, import and *
* otherwise transfer the Package with respect to any patent claims licensable *
* by the Copyright Holder that are necessarily infringed by the Package. If *
* you institute patent litigation (including a cross-claim or counterclaim) *
* against any party alleging that the Package constitutes direct or *
* contributory patent infringement, then this Artistic License to you shall *
* terminate on the date that such litigation is filed. *
* *
* (14) Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER *
* AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE *
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR *
* NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. *
* UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE *
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN *
* ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF *
* SUCH DAMAGE. *
* *
* The End *
* *
\******************************************************************************/
#include "general.h"
/* Number Handling */
int IsRealNumber(char *c) {
int i, l;
l = strlen(c);
if (l <= 0) return 0;
if (l == 1) return IsNumberDigit(c[0]);
for(i = 1; i < strlen(c); i++) {
if (c[i] == '.') return IsPosNumber(&c[i + 1]);
if (!IsNumberDigit(c[i])) return 0;
}
return (IsNumberDigit(c[0]) || IsSignDigit(c[0]));
}
int IsPosNumber(const char *c) {
int i, l;
l = strlen(c);
if (l <= 0) return 0;
for(i = 0; i < strlen(c); i++) {
if (!IsNumberDigit(c[i])) return 0;
}
return 1;
}
int IsNumber(const char *c) {
int i, l;
l = strlen(c);
if (l <= 0) return 0;
if (l == 1) return IsNumberDigit(c[0]);
for(i = 1; i < strlen(c); i++) {
if (!IsNumberDigit(c[i])) return 0;
}
return (IsNumberDigit(c[0]) || IsSignDigit(c[0]));
}
/* File Handling */
char * freadstr(FILE *fd, const char *separators) {
char *str;
int buf, icur = 0, max = 10;
str = (char *) malloc(sizeof(char) * max);
str[0] = '\0';
do {
if ((buf = fgetc(fd)) != EOF) {
if (icur == (max - 1)) {
max = max * 2;
str = (char *) realloc(str, sizeof(char) * max);
}
if (!CharIn((char) buf, separators)) {
str[icur] = (char) buf;
icur++;
str[icur] = '\0';
}
}
} while(!CharIn(buf, separators) && !feof(fd));
return str;
}
int CharIn(const char c, const char *in) {
int i;
for (i = 0; i < strlen(in); i++)
if (c == in[i]) return 1;
return 0;
}
/* string handling */
int patternmatch(char *pattern, char *thestr) {
int i, j = -1, pl = strlen(pattern), sl = strlen(thestr);
for(i = 0; i < pl; i++) {
if (pattern[i] == '*') {
do {
i++;
if (i == pl) return 1;
} while(pattern[i] == '*');
do {
j++;
if (j >= sl) return 0;
if ((thestr[j] == pattern[i]) && patternmatch(pattern + i, thestr + j)) return 1;
} while(1);
} else {
j++;
if (j >= sl) return 0;
if (pattern[i] != thestr[j]) return 0;
}
}
return (pl == sl);
}

View File

@@ -0,0 +1,204 @@
/******************************************************************************\
* *
* SimpleCUDD library (www.cs.kuleuven.be/~theo/tools/simplecudd.html) *
* SimpleCUDD was developed at Katholieke Universiteit Leuven(www.kuleuven.be) *
* *
* Copyright Katholieke Universiteit Leuven 2008 *
* *
* Author: Theofrastos Mantadelis *
* File: general.h *
* *
********************************************************************************
* *
* Artistic License 2.0 *
* *
* Copyright (c) 2000-2006, The Perl Foundation. *
* *
* Everyone is permitted to copy and distribute verbatim copies of this license *
* document, but changing it is not allowed. *
* *
* Preamble *
* *
* This license establishes the terms under which a given free software Package *
* may be copied, modified, distributed, and/or redistributed. The intent is *
* that the Copyright Holder maintains some artistic control over the *
* development of that Package while still keeping the Package available as *
* open source and free software. *
* *
* You are always permitted to make arrangements wholly outside of this license *
* directly with the Copyright Holder of a given Package. If the terms of this *
* license do not permit the full use that you propose to make of the Package, *
* you should contact the Copyright Holder and seek a different licensing *
* arrangement. *
* Definitions *
* *
* "Copyright Holder" means the individual(s) or organization(s) named in the *
* copyright notice for the entire Package. *
* *
* "Contributor" means any party that has contributed code or other material to *
* the Package, in accordance with the Copyright Holder's procedures. *
* *
* "You" and "your" means any person who would like to copy, distribute, or *
* modify the Package. *
* *
* "Package" means the collection of files distributed by the Copyright Holder, *
* and derivatives of that collection and/or of those files. A given Package *
* may consist of either the Standard Version, or a Modified Version. *
* *
* "Distribute" means providing a copy of the Package or making it accessible *
* to anyone else, or in the case of a company or organization, to others *
* outside of your company or organization. *
* *
* "Distributor Fee" means any fee that you charge for Distributing this *
* Package or providing support for this Package to another party. It does not *
* mean licensing fees. *
* *
* "Standard Version" refers to the Package if it has not been modified, or has *
* been modified only in ways explicitly requested by the Copyright Holder. *
* *
* "Modified Version" means the Package, if it has been changed, and such *
* changes were not explicitly requested by the Copyright Holder. *
* *
* "Original License" means this Artistic License as Distributed with the *
* Standard Version of the Package, in its current version or as it may be *
* modified by The Perl Foundation in the future. *
* *
* "Source" form means the source code, documentation source, and configuration *
* files for the Package. *
* *
* "Compiled" form means the compiled bytecode, object code, binary, or any *
* other form resulting from mechanical transformation or translation of the *
* Source form. *
* Permission for Use and Modification Without Distribution *
* *
* (1) You are permitted to use the Standard Version and create and use *
* Modified Versions for any purpose without restriction, provided that you do *
* not Distribute the Modified Version. *
* Permissions for Redistribution of the Standard Version *
* *
* (2) You may Distribute verbatim copies of the Source form of the Standard *
* Version of this Package in any medium without restriction, either gratis or *
* for a Distributor Fee, provided that you duplicate all of the original *
* copyright notices and associated disclaimers. At your discretion, such *
* verbatim copies may or may not include a Compiled form of the Package. *
* *
* (3) You may apply any bug fixes, portability changes, and other *
* modifications made available from the Copyright Holder. The resulting *
* Package will still be considered the Standard Version, and as such will be *
* subject to the Original License. *
* Distribution of Modified Versions of the Package as Source *
* *
* (4) You may Distribute your Modified Version as Source (either gratis or for *
* a Distributor Fee, and with or without a Compiled form of the Modified *
* Version) provided that you clearly document how it differs from the Standard *
* Version, including, but not limited to, documenting any non-standard *
* features, executables, or modules, and provided that you do at least ONE of *
* the following: *
* *
* (a) make the Modified Version available to the Copyright Holder of the *
* Standard Version, under the Original License, so that the Copyright Holder *
* may include your modifications in the Standard Version. *
* (b) ensure that installation of your Modified Version does not prevent the *
* user installing or running the Standard Version. In addition, the Modified *
* Version must bear a name that is different from the name of the Standard *
* Version. *
* (c) allow anyone who receives a copy of the Modified Version to make the *
* Source form of the Modified Version available to others under *
* (i) the Original License or *
* (ii) a license that permits the licensee to freely copy, modify and *
* redistribute the Modified Version using the same licensing terms that apply *
* to the copy that the licensee received, and requires that the Source form of *
* the Modified Version, and of any works derived from it, be made freely *
* available in that license fees are prohibited but Distributor Fees are *
* allowed. *
* Distribution of Compiled Forms of the Standard Version or Modified Versions *
* without the Source *
* *
* (5) You may Distribute Compiled forms of the Standard Version without the *
* Source, provided that you include complete instructions on how to get the *
* Source of the Standard Version. Such instructions must be valid at the time *
* of your distribution. If these instructions, at any time while you are *
* carrying out such distribution, become invalid, you must provide new *
* instructions on demand or cease further distribution. If you provide valid *
* instructions or cease distribution within thirty days after you become aware *
* that the instructions are invalid, then you do not forfeit any of your *
* rights under this license. *
* *
* (6) You may Distribute a Modified Version in Compiled form without the *
* Source, provided that you comply with Section 4 with respect to the Source *
* of the Modified Version. *
* Aggregating or Linking the Package *
* *
* (7) You may aggregate the Package (either the Standard Version or Modified *
* Version) with other packages and Distribute the resulting aggregation *
* provided that you do not charge a licensing fee for the Package. Distributor *
* Fees are permitted, and licensing fees for other components in the *
* aggregation are permitted. The terms of this license apply to the use and *
* Distribution of the Standard or Modified Versions as included in the *
* aggregation. *
* *
* (8) You are permitted to link Modified and Standard Versions with other *
* works, to embed the Package in a larger work of your own, or to build *
* stand-alone binary or bytecode versions of applications that include the *
* Package, and Distribute the result without restriction, provided the result *
* does not expose a direct interface to the Package. *
* Items That are Not Considered Part of a Modified Version *
* *
* (9) Works (including, but not limited to, modules and scripts) that merely *
* extend or make use of the Package, do not, by themselves, cause the Package *
* to be a Modified Version. In addition, such works are not considered parts *
* of the Package itself, and are not subject to the terms of this license. *
* General Provisions *
* *
* (10) Any use, modification, and distribution of the Standard or Modified *
* Versions is governed by this Artistic License. By using, modifying or *
* distributing the Package, you accept this license. Do not use, modify, or *
* distribute the Package, if you do not accept this license. *
* *
* (11) If your Modified Version has been derived from a Modified Version made *
* by someone other than you, you are nevertheless required to ensure that your *
* Modified Version complies with the requirements of this license. *
* *
* (12) This license does not grant you the right to use any trademark, service *
* mark, tradename, or logo of the Copyright Holder. *
* *
* (13) This license includes the non-exclusive, worldwide, free-of-charge *
* patent license to make, have made, use, offer to sell, sell, import and *
* otherwise transfer the Package with respect to any patent claims licensable *
* by the Copyright Holder that are necessarily infringed by the Package. If *
* you institute patent litigation (including a cross-claim or counterclaim) *
* against any party alleging that the Package constitutes direct or *
* contributory patent infringement, then this Artistic License to you shall *
* terminate on the date that such litigation is filed. *
* *
* (14) Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER *
* AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE *
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR *
* NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. *
* UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE *
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN *
* ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF *
* SUCH DAMAGE. *
* *
* The End *
* *
\******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define IsNumberDigit(c) ('0' <= c && c <= '9')
#define IsSignDigit(c) (c == '+' || c == '-')
#define isOperator(x) (x == '+' || x == '*' || x == '#' || x == '=')
#define freadline(fd) freadstr(fd, "\n");
int IsRealNumber(char *c);
int IsPosNumber(const char *c);
int IsRealNumber(char *c);
int IsNumber(const char *c);
char * freadstr(FILE *fd, const char *separators);
int CharIn(const char c, const char *in);
int patternmatch(char *pattern, char *thestr);

View File

@@ -0,0 +1,277 @@
/******************************************************************
**
** IQUEUE.C:
**
** ADT Queue Iterator Implementation
**
** This file is part of Apt Abstrct Data Types (ADT)
** Copyright (c) 1991 -- Apt Technologies
** All rights reserved
**
** The concept of an iterator for an Abstract Data Type is derived
** from research on Smalltalk.
******************************************************************/
/* ---------- C Headers */
//#include "cheaders.h"
/* ---------- Headers */
#include "adterror.h"
#include "allocate.h"
#include "iqueue.h"
/* ---------- Private Function Prototypes */
#ifdef __ANSI_C__
#else
#endif
/* ---------- Functions */
/*
**
** QueueIteratorDispose
**
*/
PUBLIC
#ifdef __ANSI_C__
void QueueIteratorDispose(QueueIterator qi)
#else
void QueueIteratorDispose(qi)
QueueIterator qi;
#endif
{
free(qi);
}
/*
**
** QueueIteratorNew
**
*/
PUBLIC
#ifdef __ANSI_C__
QueueIterator QueueIteratorNew(Queue q, int start)
#else
QueueIterator QueueIteratorNew(q,start)
Queue q;
int start;
#endif
{
QueueIterator qi;
if (q)
qi = ((QueueIterator)Allocate(sizeof(_QueueIterator)));
else {
ADTError(ADT_QueueIter, E_NullQueue, "QueueIteratorNew");
return NULL;
}
if (qi) {
qi->queue = q;
QueueIteratorAbsoluteSeek(qi, start);
} else
ADTError(ADT_QueueIter, E_Allocation, "QueueIteratorNew");
return (qi);
}
/*
**
** QueueIteratorAtTop
**
*/
PUBLIC
#ifdef __ANSI_C__
int QueueIteratorAtTop(QueueIterator qi)
#else
int QueueIteratorAtTop(qi)
QueueIterator qi;
#endif
{
if (!qi)
ADTError(ADT_QueueIter, E_NullQueueIter, "QueueIteratorAtTop");
return QueueIteratorAtPosition(qi,1);
}
/*
**
** QueueIteratorAtBottom
**
*/
PUBLIC
#ifdef __ANSI_C__
int QueueIteratorAtBottom(QueueIterator qi)
#else
int QueueIteratorAtBottom(qi)
QueueIterator qi;
#endif
{
if (!qi)
ADTError(ADT_QueueIter, E_NullQueueIter, "QueueIteratorAtBottom");
return QueueIteratorAtPosition(qi,0);
}
/*
**
** QueueIteratorAtPosition
**
*/
PUBLIC
#ifdef __ANSI_C__
int QueueIteratorAtPosition(QueueIterator qi, int position)
#else
int QueueIteratorAtPosition(qi,position)
QueueIterator qi;
int position;
#endif
{
if (!qi)
ADTError(ADT_QueueIter, E_NullQueueIter, "QueueIteratorAtPosition");
if (position <= 0)
position += (QueueSize(qi->queue) + 1);
return qi->position == position;
}
/*
**
** QueueIteratorPosition
**
*/
PUBLIC
#ifdef __ANSI_C__
int QueueIteratorPosition(QueueIterator qi)
#else
int QueueIteratorPosition(qi)
QueueIterator qi;
#endif
{
if (!qi)
ADTError(ADT_QueueIter, E_NullQueueIter, "QueueIteratorPosition");
return qi->position;
}
/*
**
** QueueIteratorCurrentData
**
*/
PUBLIC
#ifdef __ANSI_C__
void *QueueIteratorCurrentData(QueueIterator qi)
#else
void *QueueIteratorCurrentData(qi)
QueueIterator qi;
#endif
{
if (!qi)
ADTError(ADT_QueueIter, E_NullQueueIter, "QueueIteratorCurrentData");
return QueueItemElement(qi->currentItem);
}
/*
**
** QueueIteratorPreviousData
**
*/
PUBLIC
#ifdef __ANSI_C__
void *QueueIteratorPreviousData(QueueIterator qi)
#else
void *QueueIteratorPreviousData(qi)
QueueIterator qi;
#endif
{
if (!qi)
ADTError(ADT_QueueIter, E_NullQueueIter, "QueueIteratorPreviousData");
return QueueItemElement(qi->previousItem);
}
/*
**
** QueueIteratorAdvance
**
*/
PUBLIC
#ifdef __ANSI_C__
void QueueIteratorAdvance(QueueIterator qi)
#else
void QueueIteratorAdvance(qi)
QueueIterator qi;
#endif
{
if (!qi)
ADTError(ADT_QueueIter, E_NullQueueIter, "QueueIteratorAdvance");
qi->previousItem = qi->currentItem;
qi->currentItem = QueueNext(qi->previousItem);
if (qi->previousItem) qi->position++;
}
/*
**
** QueueIteratorBackup
**
*/
PUBLIC
#ifdef __ANSI_C__
void QueueIteratorBackup(QueueIterator qi)
#else
void QueueIteratorBackup(qi)
QueueIterator qi;
#endif
{
if (!qi)
ADTError(ADT_QueueIter, E_NullQueueIter, "QueueIteratorBackup");
QueueIteratorRelativeSeek(qi, -1);
}
/*
**
** QueueIteratorAbsoluteSeek
**
*/
PUBLIC
#ifdef __ANSI_C__
void QueueIteratorAbsoluteSeek(QueueIterator qi, int position)
#else
void QueueIteratorAbsoluteSeek(qi,position)
QueueIterator qi;
int position;
#endif
{
if (!qi)
ADTError(ADT_QueueIter, E_NullQueueIter, "QueueIteratorAbsoluteSeek");
if (position <= 0)
position += (QueueSize(qi->queue) + 1);
if (position <= 0)
ADTError(ADT_QueueIter, E_Seek, "QueueIteratorAbsoluteSeek");
/* Here, we know position is positive */
if (position > QueueSize(qi->queue) + 1)
qi->position = QueueSize(qi->queue) + 1;
else
qi->position = position;
qi->previousItem = QueueSeek(qi->queue,position-1);
if (qi->previousItem)
qi->currentItem = QueueNext(qi->previousItem);
else
qi->currentItem = QueueSeek(qi->queue,position);
}
/*
**
** QueueIteratorRelativeSeek
**
*/
PUBLIC
#ifdef __ANSI_C__
void QueueIteratorRelativeSeek(QueueIterator qi,int disp)
#else
void QueueIteratorRelativeSeek(qi,disp)
QueueIterator qi;
int disp;
#endif
{
if (!qi)
ADTError(ADT_QueueIter, E_NullQueueIter, "QueueIteratorRelativeSeek");
QueueIteratorAbsoluteSeek(qi,qi->position+disp);
}

View File

@@ -0,0 +1,718 @@
/******************************************************************
**
** QUEUE.C:
**
** ADT Queue Implementation
**
** This file is part of Apt Abstrct Data Types (ADT)
** Copyright (c) 1991 -- Apt Technologies
** All rights reserved
**
******************************************************************/
/* ---------- C Headers */
//#include "cheaders.h"
/* ---------- Headers */
#include "apt.h"
#include "allocate.h"
#include "pqueue.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* ---------- Private Function Prototypes */
#ifdef __ANSI_C__
PRIVATE void QueueDisposeItem(QueueItem, DisposeFunction);
PRIVATE QueueItem QueueGetItem(Queue);
PRIVATE QueueItem QueueNewItem(void*, int);
PRIVATE void QueuePutItem(Queue, QueueItem);
PRIVATE QueueItem QueueRemoveItem(Queue, QueueItem);
//PRIVATE int QueueCompareEqual(void *, void *);
#else
PRIVATE void QueueDisposeItem();
PRIVATE QueueItem QueueGetItem();
PRIVATE QueueItem QueueNewItem();
PRIVATE void QueuePutItem();
PRIVATE QueueItem QueueRemoveItem();
//PRIVATE int QueueCompareEqual();
#endif
/* ---------- Functions */
/*
**
** QueueApply
**
*/
PUBLIC
#ifdef __ANSI_C__
void QueueApply(Queue q, ApplyFunction f)
#else
void QueueApply(q,f)
Queue q;
ApplyFunction f;
#endif
{
QueueItem item;
for (item = q->head; item != NULL; item = item->next) {
(*f)(item->element);
}
}
/*
**
** QueueApply1
**
*/
PUBLIC
#ifdef __ANSI_C__
void QueueApply1(Queue q, void *p1, ApplyFunction1 f)
#else
void QueueApply1(q,p1,f)
Queue q;
void *p1;
ApplyFunction1 f;
#endif
{
QueueItem item;
for (item = q->head; item != NULL; item = item->next) {
(*f)(item->element,p1);
}
}
/*
**
** QueueApply2
**
*/
PUBLIC
#ifdef __ANSI_C__
void QueueApply2(Queue q, void *p1, void *p2, ApplyFunction2 f)
#else
void QueueApply2(q,p1,p2,f)
Queue q;
void *p1;
void *p2;
ApplyFunction2 f;
#endif
{
QueueItem item;
for (item = q->head; item != NULL; item = item->next) {
(*f)(item->element,p1,p2);
}
}
/*
**
** QueueApply3
**
*/
PUBLIC
#ifdef __ANSI_C__
void QueueApply3(Queue q, void *p1, void* p2, void *p3, ApplyFunction3 f)
#else
void QueueApply3(q,p1,p2,p3,f)
Queue q;
void *p1;
void *p2;
void *p3;
ApplyFunction3 f;
#endif
{
QueueItem item;
for (item = q->head; item != NULL; item = item->next) {
(*f)(item->element,p1,p2,p3);
}
}
/*
**
** QueueCAR
**
*/
PUBLIC
#ifdef __ANSI_C__
void *QueueCAR(Queue q)
#else
void *QueueCAR(q)
Queue q;
#endif
{
if (q != NULL && q->head != NULL)
return QueueItemElement(q->head);
return NULL;
}
/*
**
** QueueCDR
**
*/
PUBLIC
#ifdef __ANSI_C__
Queue QueueCDR(Queue q)
#else
Queue QueueCDR(q)
Queue q;
#endif
{
if (q != NULL && q->head != NULL) {
Queue new = QueueNew();
new->head = q->head->next;
new->tail = new->head != NULL ? q->tail : NULL;
new->size = q->size-1;
return new;
} else
return NULL;
}
/*
**
** QueueDispose
**
*/
PUBLIC
#ifdef __ANSI_C__
void QueueDispose(Queue q, DisposeFunction f)
#else
void QueueDispose(q,f)
Queue q;
DisposeFunction f;
#endif
{
QueueItem item;
QueueItem next = NULL;
for (item = q->head; item != NULL; item = next) {
next = item->next;
QueueDisposeItem(item,f);
}
free(q);
}
/*
**
** QueueDisposeItem
**
*/
PRIVATE
#ifdef __ANSI_C__
void QueueDisposeItem(QueueItem item, DisposeFunction f)
#else
void QueueDisposeItem(item,f)
QueueItem item;
DisposeFunction f;
#endif
{
if (f) (*f)(item->element);
free(item);
}
/*
**
** QueueFind
**
*/
PUBLIC
#ifdef __ANSI_C__
void *QueueFind(Queue q, void *element, ComparisonFunction f)
#else
void *QueueFind(q,element,f)
Queue q;
void *element;
ComparisonFunction f;
#endif
{
QueueItem item;
for (item = q->head; item != NULL; item = item->next) {
if ((*f)(element,item->element) == 0) break;
}
return (item != NULL ? item->element : NULL);
}
/*
**
** QueueFindAndRemove
**
*/
PUBLIC
#ifdef __ANSI_C__
void *QueueFindAndRemove(Queue q, void *element,
ComparisonFunction f)
#else
void *QueueFindAndRemove(q, element, f)
Queue q;
void *element;
ComparisonFunction f;
#endif
{
QueueItem item;
for (item = q->head; item != NULL; item = item->next) {
if ((*f)(element,item->element) == 0) break;
}
item = QueueRemoveItem(q,item);
return (item != NULL ? item->element : NULL);
}
/*
**
** QueueFindAndRemoveType
**
*/
PUBLIC
#ifdef __ANSI_C__
void *QueueFindAndRemoveType(Queue q, void *element,
ComparisonFunction f, int type)
#else
void *QueueFindAndRemoveType(q, element, f, type)
Queue q;
void *element;
ComparisonFunction f;
int type;
#endif
{
QueueItem item;
for (item = q->head; item != NULL; item = item->next) {
if ((*f)(element,item->element) == 0 && item->type == type) break;
}
item = QueueRemoveItem(q,item);
return (item != NULL ? item->element : NULL);
}
/*
**
** QueueFindType
**
*/
PUBLIC
#ifdef __ANSI_C__
void *QueueFindType(Queue q, int type)
#else
void *QueueFindType(q,type)
Queue q;
int type;
#endif
{
QueueItem item;
for (item = q->head; item != NULL; item = item->next) {
if (item->type == type) break;
}
return (item != NULL ? item->element : NULL);
}
/*
**
** QueueFindTypeAndRemove
**
*/
PUBLIC
#ifdef __ANSI_C__
void *QueueFindTypeAndRemove(Queue q, int type)
#else
void *QueueFindTypeAndRemove(q,type)
Queue q;
int type;
#endif
{
QueueItem item;
for (item = q->head; item != NULL; item = item->next) {
if (item->type == type) break;
}
return (QueueRemoveItem(q,item));
}
/*
**
** QueueGet
**
*/
PUBLIC
#ifdef __ANSI_C__
void *QueueGet(Queue q)
#else
void *QueueGet(q)
Queue q;
#endif
{
void *element;
QueueItem item;
item = QueueGetItem(q);
if (item) {
element = item->element;
QueueDisposeItem(item,NULL);
}
else element = NULL;
return (element);
}
/*
**
** QueueGetItem
**
*/
PRIVATE
#ifdef __ANSI_C__
QueueItem QueueGetItem(Queue q)
#else
QueueItem QueueGetItem(q)
Queue q;
#endif
{
QueueItem item;
if (q->head) {
item = q->head;
q->head = q->head->next;
q->size--;
}
else item = NULL;
return (item);
}
/*
**
** QueueHead
**
*/
PUBLIC
#ifdef __ANSI_C__
QueueItem QueueHead(Queue q)
#else
QueueItem QueueHead(q)
Queue q;
#endif
{
return q != NULL ? q->head : NULL;
}
/*
**
** QueueItemElement
**
*/
PUBLIC
#ifdef __ANSI_C__
void *QueueItemElement(QueueItem item)
#else
void *QueueItemElement(item)
QueueItem item;
#endif
{
return (item->element);
}
/*
**
** QueueItemType
**
*/
PUBLIC
#ifdef __ANSI_C__
int QueueItemType(QueueItem item)
#else
int QueueItemType(item)
QueueItem item;
#endif
{
return (item->type);
}
/*
**
** QueueLook
**
*/
PUBLIC
#ifdef __ANSI_C__
void *QueueLook(Queue q)
#else
void *QueueLook(q)
Queue q;
#endif
{
QueueItem item;
item = q->head;
return (item != NULL ? item->element : NULL);
}
/*
**
** QueueNew
**
*/
PUBLIC
#ifdef __ANSI_C__
Queue QueueNew(void)
#else
Queue QueueNew()
#endif
{
Queue q;
q = ((Queue)Allocate(sizeof(_Queue)));
if (q) {
q->head = q->tail = NULL;
q->size = 0;
}
return (q);
}
/*
**
** QueueNewItem
**
*/
PRIVATE
#ifdef __ANSI_C__
QueueItem QueueNewItem(void *element, int type)
#else
QueueItem QueueNewItem(element,type)
void *element;
int type;
#endif
{
QueueItem item;
item = ((QueueItem)Allocate(sizeof(_QueueItem)));
if (item) {
item->element = element;
item->type = type;
item->next = NULL;
}
return (item);
}
/*
**
** QueueNext
**
*/
PUBLIC
#ifdef __ANSI_C__
QueueItem QueueNext(QueueItem item)
#else
QueueItem QueueNext(item)
QueueItem item;
#endif
{
return item != NULL ? item->next : NULL;
}
/*
**
** QueuePut
**
*/
PUBLIC
#ifdef __ANSI_C__
void QueuePut(Queue q, void *element, int type)
#else
void QueuePut(q,element,type)
Queue q;
void *element;
int type;
#endif
{
QueueItem item;
item = QueueNewItem(element,type);
QueuePutItem(q,item);
}
/*
**
** QueuePutItem
**
*/
PRIVATE
#ifdef __ANSI_C__
void QueuePutItem(Queue q, QueueItem item)
#else
void QueuePutItem(q,item)
Queue q;
QueueItem item;
#endif
{
if (q->head == NULL) {
q->head = q->tail = item;
} else {
q->tail->next = item;
q->tail = q->tail->next;
}
q->size++;
}
/*
**
** QueuePutOnPriority
**
*/
PUBLIC
#ifdef __ANSI_C__
void QueuePutOnPriority(Queue q, void *element, int type,
ComparisonFunction f)
#else
void QueuePutOnPriority(q,element,type,f)
Queue q;
void *element;
int type;
ComparisonFunction f;
#endif
{
QueueItem item;
item = QueueNewItem(element,type);
//fprintf(stderr,"searching for location using %p.\n",f);
if (f == NULL){
//fprintf(stderr,"comparing function is null %f \n",f);
exit(1);
QueuePutItem(q,item);
}else {
if (q->head == NULL) QueuePutItem(q,item);
else {
QueueItem p, lastp = NULL;
for (p = q->head; p != NULL; p = p->next) {
int cval =(*f)(element,p->element);
if (cval<0){
// fprintf(stderr,"%i <=> %i == %i\n",*((int *) element),*((int *)(p->element)),
// cval);
break;
}
lastp = p;
}
if (p == q->head) {
item->next = q->head;
q->head = item;
} else if (p == NULL) {
q->tail->next = item;
q->tail = q->tail->next;
} else {
item->next = p;
lastp->next = item;
}
q->size++;
}
}
}
/*
**
** QueueRemoveItem
**
*/
PRIVATE
#ifdef __ANSI_C__
QueueItem QueueRemoveItem(Queue q, QueueItem item)
#else
QueueItem QueueRemoveItem(q,item)
Queue q;
QueueItem item;
#endif
{
QueueItem this, prev = NULL;
if (q == NULL) return (NULL);
if (item == NULL) return (NULL);
this = q->head;
while (this && this != item) {
prev = this; this = this->next;
}
if (this == NULL) return (NULL);
if (this == q->head) q->head = item->next;
if (this == q->tail) q->tail = prev;
if (prev) prev->next = this->next;
q->size--;
return (item);
}
/*
**
** QueueSeek
**
*/
PUBLIC
#ifdef __ANSI_C__
QueueItem QueueSeek(Queue q, int position)
#else
QueueItem QueueSeek(q,position)
Queue q;
int position;
#endif
{
QueueItem item;
#if 0
/* Allow single-level negative addressing of queue items */
if (position <= 0)
position += QueueSize(q);
#endif
/* Seeks which fail will result in NULL, not error conditions */
if (position <= 0 || position > QueueSize(q))
return NULL;
item = QueueHead(q);
while (--position > 0)
item = QueueNext(item);
return item;
}
/*
**
** QueueSize
**
*/
PUBLIC
#ifdef __ANSI_C__
int QueueSize(Queue q)
#else
int QueueSize(q)
Queue q;
#endif
{
return q != NULL ? q->size : 0;
}
/*
**
** QueueTail
**
*/
PUBLIC
#ifdef __ANSI_C__
QueueItem QueueTail(Queue q)
#else
QueueItem QueueTail(q)
Queue q;
#endif
{
return q != NULL ? q->tail : NULL;
}
#ifdef UNUSED
PRIVATE
#ifdef __ANSI_C__
int QueueCompareEqual(void *x, void *y)
#else
int QueueCompareEqual(x,y)
void *x, *y;
#endif
{
return 0;
}
#endif

View File

@@ -0,0 +1,94 @@
/******************************************************************
**
** QUEUE.H:
**
** ADT Queue Implementation
**
** This file is part of Apt Abstract Data Types (ADT)
** Copyright (c) 1991 -- Apt Technologies
** All rights reserved
**
******************************************************************/
//http://www.koders.com/c/fid7B82D8DDECE4EDC672F17D970458033C4079A615.aspx?s=queue
/*
** This ADT, originally written in 1989, provides a general queue
** implementation--in C--which is the equivalent of the Java Vector.
*/
#ifndef QUEUE_H
#define QUEUE_H
/* ---------- Headers */
#include "apt.h"
/* ---------- Types */
typedef struct _QueueItem {
void *element;
int type;
struct _QueueItem *next;
} _QueueItem, *QueueItem;
typedef struct _Queue {
struct _QueueItem *head;
struct _QueueItem *tail;
int size;
} _Queue, *Queue;
/* ---------- Exported Function Prototypes */
#ifdef __ANSI_C__
void QueueApply(Queue, ApplyFunction);
void QueueApply1(Queue, void*, ApplyFunction1);
void QueueApply2(Queue, void*, void*, ApplyFunction2);
void QueueApply3(Queue, void*, void*, void*, ApplyFunction3);
void *QueueCAR(Queue);
Queue QueueCDR(Queue);
void QueueDispose(Queue, DisposeFunction);
void *QueueFind(Queue, void*, ComparisonFunction);
void *QueueFindAndRemove(Queue, void*, ComparisonFunction);
void *QueueFindAndRemoveType(Queue, void*, ComparisonFunction, int);
void *QueueFindType(Queue, int);
void *QueueFindTypeAndRemove(Queue, int);
void *QueueGet(Queue);
QueueItem QueueHead(Queue);
void *QueueItemElement(QueueItem);
int QueueItemType(QueueItem);
void *QueueLook(Queue);
Queue QueueNew(void);
QueueItem QueueNext(QueueItem);
void QueuePut(Queue, void*, int);
void QueuePutOnPriority(Queue, void*, int, ComparisonFunction);
QueueItem QueueSeek(Queue,int);
int QueueSize(Queue);
QueueItem QueueTail(Queue);
#else
void QueueApply();
void QueueApply1();
void QueueApply2();
void QueueApply3();
void *QueueCAR();
Queue QueueCDR();
void QueueDispose();
void *QueueFind();
void *QueueFindAndRemove();
void *QueueFindAndRemoveType();
void *QueueFindType();
void *QueueFindTypeAndRemove();
void *QueueGet();
QueueItem QueueHead();
void *QueueItemElement();
int QueueItemType();
void *QueueLook();
Queue QueueNew();
QueueItem QueueNext();
void QueuePut();
void QueuePutOnPriority();
QueueItem QueueSeek();
int QueueSize();
QueueItem QueueTail();
#endif /* __ANSI_C__ */
#endif /* QUEUE_H */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,294 @@
/******************************************************************************\
* *
* SimpleCUDD library (www.cs.kuleuven.be/~theo/tools/simplecudd.html) *
* SimpleCUDD was developed at Katholieke Universiteit Leuven(www.kuleuven.be) *
* *
* Copyright T. Mantadelis, A. Kimmig, B. Gutmann *
* and Katholieke Universiteit Leuven 2008 *
* *
* Author: Bernd Gutmann *
* File: problogmath.c *
* $Date:: 2009-12-06 00:55:33 +0100 (Sun, 06 Dec 2009) $ *
* $Revision:: 2919 $ *
* *
* *
********************************************************************************
* *
* The "Artistic License" *
* *
* Preamble *
* *
* The intent of this document is to state the conditions under which a *
* Package may be copied, such that the Copyright Holder maintains some *
* semblance of artistic control over the development of the package, *
* while giving the users of the package the right to use and distribute *
* the Package in a more-or-less customary fashion, plus the right to make *
* reasonable modifications. *
* *
* Definitions: *
* *
* "Package" refers to the collection of files distributed by the *
* Copyright Holder, and derivatives of that collection of files *
* created through textual modification. *
* *
* "Standard Version" refers to such a Package if it has not been *
* modified, or has been modified in accordance with the wishes *
* of the Copyright Holder as specified below. *
* *
* "Copyright Holder" is whoever is named in the copyright or *
* copyrights for the package. *
* *
* "You" is you, if you're thinking about copying or distributing *
* this Package. *
* *
* "Reasonable copying fee" is whatever you can justify on the *
* basis of media cost, duplication charges, time of people involved, *
* and so on. (You will not be required to justify it to the *
* Copyright Holder, but only to the computing community at large *
* as a market that must bear the fee.) *
* *
* "Freely Available" means that no fee is charged for the item *
* itself, though there may be fees involved in handling the item. *
* It also means that recipients of the item may redistribute it *
* under the same conditions they received it. *
* *
* 1. You may make and give away verbatim copies of the source form of the *
* Standard Version of this Package without restriction, provided that you *
* duplicate all of the original copyright notices and associated disclaimers. *
* *
* 2. You may apply bug fixes, portability fixes and other modifications *
* derived from the Public Domain or from the Copyright Holder. A Package *
* modified in such a way shall still be considered the Standard Version. *
* *
* 3. You may otherwise modify your copy of this Package in any way, provided *
* that you insert a prominent notice in each changed file stating how and *
* when you changed that file, and provided that you do at least ONE of the *
* following: *
* *
* a) place your modifications in the Public Domain or otherwise make them *
* Freely Available, such as by posting said modifications to Usenet or *
* an equivalent medium, or placing the modifications on a major archive *
* site such as uunet.uu.net, or by allowing the Copyright Holder to include *
* your modifications in the Standard Version of the Package. *
* *
* b) use the modified Package only within your corporation or organization. *
* *
* c) rename any non-standard executables so the names do not conflict *
* with standard executables, which must also be provided, and provide *
* a separate manual page for each non-standard executable that clearly *
* documents how it differs from the Standard Version. *
* *
* d) make other distribution arrangements with the Copyright Holder. *
* *
* 4. You may distribute the programs of this Package in object code or *
* executable form, provided that you do at least ONE of the following: *
* *
* a) distribute a Standard Version of the executables and library files, *
* together with instructions (in the manual page or equivalent) on where *
* to get the Standard Version. *
* *
* b) accompany the distribution with the machine-readable source of *
* the Package with your modifications. *
* *
* c) give non-standard executables non-standard names, and clearly *
* document the differences in manual pages (or equivalent), together *
* with instructions on where to get the Standard Version. *
* *
* d) make other distribution arrangements with the Copyright Holder. *
* *
* 5. You may charge a reasonable copying fee for any distribution of this *
* Package. You may charge any fee you choose for support of this *
* Package. You may not charge a fee for this Package itself. However, *
* you may distribute this Package in aggregate with other (possibly *
* commercial) programs as part of a larger (possibly commercial) software *
* distribution provided that you do not advertise this Package as a *
* product of your own. You may embed this Package's interpreter within *
* an executable of yours (by linking); this shall be construed as a mere *
* form of aggregation, provided that the complete Standard Version of the *
* interpreter is so embedded. *
* *
* 6. The scripts and library files supplied as input to or produced as *
* output from the programs of this Package do not automatically fall *
* under the copyright of this Package, but belong to whoever generated *
* them, and may be sold commercially, and may be aggregated with this *
* Package. If such scripts or library files are aggregated with this *
* Package via the so-called "undump" or "unexec" methods of producing a *
* binary executable image, then distribution of such an image shall *
* neither be construed as a distribution of this Package nor shall it *
* fall under the restrictions of Paragraphs 3 and 4, provided that you do *
* not represent such an executable image as a Standard Version of this *
* Package. *
* *
* 7. C subroutines (or comparably compiled subroutines in other *
* languages) supplied by you and linked into this Package in order to *
* emulate subroutines and variables of the language defined by this *
* Package shall not be considered part of this Package, but are the *
* equivalent of input as in Paragraph 6, provided these subroutines do *
* not change the language in any way that would cause it to fail the *
* regression tests for the language. *
* *
* 8. Aggregation of this Package with a commercial distribution is always *
* permitted provided that the use of this Package is embedded; that is, *
* when no overt attempt is made to make this Package's interfaces visible *
* to the end user of the commercial distribution. Such use shall not be *
* construed as a distribution of this Package. *
* *
* 9. The name of the Copyright Holder may not be used to endorse or promote *
* products derived from this software without specific prior written *
* permission. *
* *
* 10. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR *
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED *
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. *
* *
* The End *
* *
\******************************************************************************/
#include "general.h"
#include "problogmath.h"
double sigmoid(double x, double slope) {
return 1.0 / (1.0 + exp(-x * slope));
}
// This function calculates the accumulated density of the normal distribution
// For details see G. Marsaglia, Evaluating the Normal Distribution, Journal of Statistical Software, 2004:11(4).
double Phi(double x) {
double s=x;
double t=0.0;
double b=x;
double q=x*x;
double i=1;
// if the value is too small or too big, return
// 0/1 to avoid long computations
if (x < -10.0) {
return 0.0;
}
if (x > 10.0) {
return 1.0;
}
// t is the value from last iteration
// s is the value from the current iteration
// iterate until they are equal
while(fabs(s-t) >= DBL_MIN) {
t=s;
i+=2;
b*=q/i;
s+=b;
}
return 0.5+s*exp(-0.5*q-0.91893853320467274178);
}
// integrates the normal distribution over [low,high]
double cumulative_normal(double low, double high, double mu, double sigma) {
return Phi((high-mu)/sigma) - Phi((low-mu)/sigma);
}
// evaluates the density of the normal distribution
double normal(double x, double mu,double sigma) {
double inner=(x-mu)/sigma;
double denom=sigma*sqrt(2*3.14159265358979323846);
return exp(-inner*inner/2)/denom;
}
double cumulative_normal_dmu(double low, double high,double mu,double sigma) {
return normal(low,mu,sigma) - normal(high,mu,sigma);
}
double cumulative_normal_dsigma(double low, double high,double mu,double sigma) {
return ((mu-high)*normal(high,mu,sigma) - (mu-low)*normal(low,mu,sigma))/sigma;
}
// this function parses two strings "$a;$b" and "???_???l$ch$d" where $a-$d are (real) numbers
// it is used to parse in the parameters of continues variables from the input file
density_integral parse_density_integral_string(char *input, char *variablename) {
density_integral result;
int i;
char garbage[64], s1[64],s2[64],s3[64],s4[64];
if(sscanf(input, "%64[^;];%64[^;]", s1,s2) != 2) {
fprintf(stderr, "Error at parsing the string %s in the function parse_density_integral_string\n",input);
fprintf(stderr, "The string should contain 2 fields seperated by ; characters.\n");
exit(EXIT_FAILURE);
}
if (IsRealNumber(s1)) {
result.mu=atof(s1);
} else {
fprintf(stderr, "Error at parsing the string %s in the function parse_density_integral_string\n",input);
fprintf(stderr, "%s is not a number\n",s1);
exit(EXIT_FAILURE);
}
if (IsRealNumber(s2)) {
result.sigma=atof(s2);
} else {
fprintf(stderr, "Error at parsing the string %s in the function parse_density_integral_string\n",input);
fprintf(stderr, "%s is not a number\n",s2);
exit(EXIT_FAILURE);
}
if (result.sigma<=0) {
fprintf(stderr, "Error at parsing the string %s in the function parse_density_integral_string",input);
fprintf(stderr, "The value for sigma has to be larger than 0.\n");
exit(EXIT_FAILURE);
}
if (sscanf(variablename,"%64[^lh]l%64[^lh]h%64[^lh]",garbage,s3,s4) != 3) {
fprintf(stderr, "Error at parsing the string %s in the function parse_density_integral_string\n",variablename);
fprintf(stderr, "The string should contain 2 fields seperated by ; characters.\n");
exit(EXIT_FAILURE);
}
// replace the d by . in s1 and s2
for(i=0; s3[i]!='\0' ; i++) {
if (s3[i]=='d') {
s3[i]='.';
}
if (s3[i]=='m') {
s3[i]='-';
}
}
for(i=0; s4[i]!='\0' ; i++) {
if (s4[i]=='d') {
s4[i]='.';
}
if (s4[i]=='m') {
s4[i]='-';
}
}
if (IsRealNumber(s3)) {
result.low=atof(s3);
} else {
fprintf(stderr, "Error at parsing the string %s in the function parse_density_integral_string\n",input);
fprintf(stderr, "%s is not a number\n",s1);
exit(EXIT_FAILURE);
}
if (IsRealNumber(s4)) {
result.high=atof(s4);
} else {
fprintf(stderr, "Error ar parsing the string %s in the function parse_density_integral_string\n",input);
fprintf(stderr, "%s is not a number\n",s1);
exit(EXIT_FAILURE);
}
if (result.low>result.high) {
fprintf(stderr, "Error ar parsing the string %s in the function parse_density_integral_string\n",input);
fprintf(stderr, "The value for low has to be larger than then value for high.\n");
exit(EXIT_FAILURE);
}
return result;
}

View File

@@ -0,0 +1,169 @@
/******************************************************************************\
* *
* SimpleCUDD library (www.cs.kuleuven.be/~theo/tools/simplecudd.html) *
* SimpleCUDD was developed at Katholieke Universiteit Leuven(www.kuleuven.be) *
* *
* Copyright T. Mantadelis, A. Kimmig, B. Gutmann *
* and Katholieke Universiteit Leuven 2008 *
* *
* Author: Bernd Gutmann *
* File: problogmath.h *
* $Date:: 2009-08-17 17:45:21 +0200 (Mon, 17 Aug 2009) $ *
* $Revision:: 1900 $ *
* *
* *
********************************************************************************
* *
* The "Artistic License" *
* *
* Preamble *
* *
* The intent of this document is to state the conditions under which a *
* Package may be copied, such that the Copyright Holder maintains some *
* semblance of artistic control over the development of the package, *
* while giving the users of the package the right to use and distribute *
* the Package in a more-or-less customary fashion, plus the right to make *
* reasonable modifications. *
* *
* Definitions: *
* *
* "Package" refers to the collection of files distributed by the *
* Copyright Holder, and derivatives of that collection of files *
* created through textual modification. *
* *
* "Standard Version" refers to such a Package if it has not been *
* modified, or has been modified in accordance with the wishes *
* of the Copyright Holder as specified below. *
* *
* "Copyright Holder" is whoever is named in the copyright or *
* copyrights for the package. *
* *
* "You" is you, if you're thinking about copying or distributing *
* this Package. *
* *
* "Reasonable copying fee" is whatever you can justify on the *
* basis of media cost, duplication charges, time of people involved, *
* and so on. (You will not be required to justify it to the *
* Copyright Holder, but only to the computing community at large *
* as a market that must bear the fee.) *
* *
* "Freely Available" means that no fee is charged for the item *
* itself, though there may be fees involved in handling the item. *
* It also means that recipients of the item may redistribute it *
* under the same conditions they received it. *
* *
* 1. You may make and give away verbatim copies of the source form of the *
* Standard Version of this Package without restriction, provided that you *
* duplicate all of the original copyright notices and associated disclaimers. *
* *
* 2. You may apply bug fixes, portability fixes and other modifications *
* derived from the Public Domain or from the Copyright Holder. A Package *
* modified in such a way shall still be considered the Standard Version. *
* *
* 3. You may otherwise modify your copy of this Package in any way, provided *
* that you insert a prominent notice in each changed file stating how and *
* when you changed that file, and provided that you do at least ONE of the *
* following: *
* *
* a) place your modifications in the Public Domain or otherwise make them *
* Freely Available, such as by posting said modifications to Usenet or *
* an equivalent medium, or placing the modifications on a major archive *
* site such as uunet.uu.net, or by allowing the Copyright Holder to include *
* your modifications in the Standard Version of the Package. *
* *
* b) use the modified Package only within your corporation or organization. *
* *
* c) rename any non-standard executables so the names do not conflict *
* with standard executables, which must also be provided, and provide *
* a separate manual page for each non-standard executable that clearly *
* documents how it differs from the Standard Version. *
* *
* d) make other distribution arrangements with the Copyright Holder. *
* *
* 4. You may distribute the programs of this Package in object code or *
* executable form, provided that you do at least ONE of the following: *
* *
* a) distribute a Standard Version of the executables and library files, *
* together with instructions (in the manual page or equivalent) on where *
* to get the Standard Version. *
* *
* b) accompany the distribution with the machine-readable source of *
* the Package with your modifications. *
* *
* c) give non-standard executables non-standard names, and clearly *
* document the differences in manual pages (or equivalent), together *
* with instructions on where to get the Standard Version. *
* *
* d) make other distribution arrangements with the Copyright Holder. *
* *
* 5. You may charge a reasonable copying fee for any distribution of this *
* Package. You may charge any fee you choose for support of this *
* Package. You may not charge a fee for this Package itself. However, *
* you may distribute this Package in aggregate with other (possibly *
* commercial) programs as part of a larger (possibly commercial) software *
* distribution provided that you do not advertise this Package as a *
* product of your own. You may embed this Package's interpreter within *
* an executable of yours (by linking); this shall be construed as a mere *
* form of aggregation, provided that the complete Standard Version of the *
* interpreter is so embedded. *
* *
* 6. The scripts and library files supplied as input to or produced as *
* output from the programs of this Package do not automatically fall *
* under the copyright of this Package, but belong to whoever generated *
* them, and may be sold commercially, and may be aggregated with this *
* Package. If such scripts or library files are aggregated with this *
* Package via the so-called "undump" or "unexec" methods of producing a *
* binary executable image, then distribution of such an image shall *
* neither be construed as a distribution of this Package nor shall it *
* fall under the restrictions of Paragraphs 3 and 4, provided that you do *
* not represent such an executable image as a Standard Version of this *
* Package. *
* *
* 7. C subroutines (or comparably compiled subroutines in other *
* languages) supplied by you and linked into this Package in order to *
* emulate subroutines and variables of the language defined by this *
* Package shall not be considered part of this Package, but are the *
* equivalent of input as in Paragraph 6, provided these subroutines do *
* not change the language in any way that would cause it to fail the *
* regression tests for the language. *
* *
* 8. Aggregation of this Package with a commercial distribution is always *
* permitted provided that the use of this Package is embedded; that is, *
* when no overt attempt is made to make this Package's interfaces visible *
* to the end user of the commercial distribution. Such use shall not be *
* construed as a distribution of this Package. *
* *
* 9. The name of the Copyright Holder may not be used to endorse or promote *
* products derived from this software without specific prior written *
* permission. *
* *
* 10. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR *
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED *
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. *
* *
* The End *
* *
\******************************************************************************/
#include <math.h>
#include <float.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct _density_integral {
double low;
double high;
double mu;
double sigma;
} density_integral;
double sigmoid(double x, double slope);
double normal(double x, double mu,double sigma);
double Phi(double x);
double cumulative_normal(double low, double high, double sigma, double mu);
double cumulative_normal_dmu(double low, double high,double mu,double sigma);
double cumulative_normal_dsigma(double low, double high,double mu,double sigma);
density_integral parse_density_integral_string(char *input, char *variablename);

View File

@@ -0,0 +1,52 @@
#include <stdio.h>
#include "pqueue.h"
#include "iqueue.h"
//http://www.koders.com/c/fid7B82D8DDECE4EDC672F17D970458033C4079A615.aspx?s=queue
#define INT_VALUE 1000
//typedef int (*ComparisonFunction)(void*, void*);
int compare_int (const int *a, const int *b)
{
fprintf(stderr,"comparing %i %i \n",*a,*b);
int temp = *a - *b;
// return (a<b) ? 1 : -1;
// return -1;
if (temp < 0)
return 1;
else if (temp > 0)
return -1;
else
return 0;
}
int main (int argc, char* argv[]) {
int val1 = 1;
int val2 = 2;
int val3 = 3;
int val4 = 4;
Queue q = QueueNew();
QueuePutOnPriority(q, &val1, INT_VALUE,(ComparisonFunction)compare_int);
QueuePutOnPriority(q, &val3, INT_VALUE,(ComparisonFunction)compare_int);
QueuePutOnPriority(q, &val2, INT_VALUE,(ComparisonFunction)compare_int);
QueuePutOnPriority(q, &val4, INT_VALUE,(ComparisonFunction)compare_int);
QueueItem qptr = q->head;
while (qptr != NULL) {
int* val = (int*) qptr->element;
printf("value: %d\n", *val);
qptr = qptr->next;
}
QueueIterator qiter = QueueIteratorNew(q, 1);
while (qiter->currentItem != NULL) {
int* val = (int*) qiter->currentItem->element;
printf("iterator value: %d\n", *val);
QueueIteratorAdvance(qiter);
}
}

File diff suppressed because it is too large Load Diff