📄 pelutils.h
字号:
/* ***************************************************************** This file, and all other pel*.h and pel*.cc files in the Gambitsource code, are derived from the source code for Pelican, animplementation of the Huber-Sturmfels algorithm for solving sparsesystems of polynomials written by Birk Huber. That code in turnincorporated the source code for HOMPACK and Qhull, which are includedhere after being modified in the construction of both Pelican andGambit. We are grateful to the authors of Pelican, Qhull, andHOMPACK, for code that has been enormously useful in Gambit. More information about Qhull can be obtained from:http://www.geom.edu/software/qhull/ For more information concerning HOMPACK see:http://netlib2.cs.utk.edu/hompack/***************************************************************** *//* This file contains the header information that had been in globals.h,and also the various header files that formerly resided in the Utilssubdirectory of the Pelican distribution. We ae gathering it all togetherwith the intent of putting it into a black box, making sure that it has nodependencies on the rest of the code.*/#define LOG_PRINT#ifndef PELUTILS#define PELUTILS#include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>#include <time.h>#include <malloc.h>/*#define Pel_Out stdout#define Pel_Err stderr#define Pel_In stdin#define Pel_Log stdout*//**************************************************************************//********************* definitions from Atom_Types.h **********************//**************************************************************************//*** copyright (c) 1995 Birk Huber*//* ** The types wich can be stored in the left and right fields** of a node and the integers that represent them:** ** Note type names should all consist of 3 or 4 CAPITOL letters** These are not nescessarily constants the interpreter should** know about but constants wich the diferent modules may need** to interpret the data sent to them.*/#ifndef ATOM_INC#define ATOM_INC 1 #define NPTR 100 /* A pointer to a node pointer*/ #define NODE 110 /* A node pointer */ #define STR 120 /* a string (currently a pntr to a C-string)*/ #define IDF 121 /* a string (currently a pntr to a C-string)*/ #define ERR 123 /* a string (currently a pntr to a C-string)*/ #define PROC 130 /* Scalor Types */ #define INT 210 /* an int (will one always fit in a (char *)*/ #define DBL 220 /* a double (will it fit ) */ #define CMPX 230 /* NOT SET UP YET a complex */ #define POLY 240 /* NOT SET UP YET a pointer to a polynomial */ /* Vector Types */ #define NMTX 300 /* a pntr to a mtrx of nodeptrs */ #define IMTX 310 /* a pointer to an integer matrix (Imatrix)*/ #define DMTX 320 /* a pntr to a mtrx of doubles */ #define CMTX 330 /* a pntr to a mtrx of complexes */ #define PMTX 340 /* a pntr to a mtrx of Polynomials */ /* Convex Geometry */ #define PNT 510 /* point in affine space */ #define PCFG 520 /* point configuration */ #define ASET 530 /* An Aset */ #define CELL 540 /* An Icell (from cly_package)*/ /* End Type Definitions *//* some other usefull constants */#define LEFT 20#define RIGHT 10#define TRUE 1#define FALSE 0#endif/**************************************************************************//************************ definitions from Mem.h **************************//**************************************************************************//*** copyright (c) 1995 Birk Huber*//* ** elements of type node are pointers to an s-expression structure** whose elements are a left (right)value and a left (right) type.** The type is an integer, refering to the constants in XXX.h,** and the left will be a value of the associated type,(stored as** a char pointer). ***/#define RIGHT 10#define LEFT 20typedef struct node_t *node; typedef struct local_t { struct local_t *next; node *val;} *local_v;#ifdef Mem_Internalstruct node_t { int LT, RT, Mark; union { void *ptr; int ival; double dval; } L, R;}; #define Node_LT(n) ((n->LT))#define Node_L(n) ((n->L))#define Node_RT(n) ((n->RT))#define Node_R(n) ((n->R))#endif#define LOCS(n) struct local_t Loc[(n)]; int loc_ct=0;void node_push_local(local_v loc, node * val);#define PUSH_LOC(V) node_push_local(Loc+(loc_ct++),(&(V)));#define POP_LOCS() while(--loc_ct>=0) node_pop_local();/* Allocation Functions */int node_init_store(void); /*reserves space for the node stack */void node_free_store(void); /*frees node stack*/node node_new(void); /*allocates a node from stack*/char *mem_strdup(char *); /*call strdup, with bookkeeping*/ void *mem_malloc(int); /* call malloc,keep running total of calls*/ void mem_free(void *); /* call free, keep running total *//*** node_push_local and node_pop_local maintain the ** the garbage collector's list of starting points.** any function which (indirectly) calls new_node must** protect any local variables it uses, by putting their ** addresses on the list with node_push_local(&ptr) and** must have a cooresponding call to node_pop_local before** returning */void node_push_local(local_v, node *); void node_pop_local(void); /* ** access functions */node node_set_ptr(node N,void *v, int tp, int side);node node_set_int(node N,int v, int tp, int side);node node_set_double(node N,double v, int tp, int side);int node_get_int(node N, int side);double node_get_double(node N, int side);void *node_get_ptr(node N, int side);int node_get_type(node g,int side);node Cons(node,node);node Car(node);node Cdr(node);int node_atomp(node);int node_nullp(node);node node_print(node);/**************************************************************************//************************ definitions from error.h ************************//**************************************************************************/#define GAMBIT_EXCEPTIONS#ifdef GAMBIT_EXCEPTIONS#include "base/gmisc.h"#include "base/gtext.h"class ErrorInPelican : public gException {public: virtual ~ErrorInPelican(); gText Description(void) const;};#endifvoid bad_error(char *);void warning(char *);/**************************************************************************//******************* header information from globals.h ********************//**************************************************************************/#ifndef PI #define PI (double)3.14159265358979323846264338328#endif#ifndef size_t #define size_t int#endif#define TRUE 1#define FALSE 0#define min(i,j) ((i) < (j) ? (i): (j))#define USE_HOMPACK 1#define USE_PNEWTON 2#ifndef IN_GLOBALS_C extern FILE *Pel_Err; extern FILE *Pel_Out; extern FILE *Pel_Log; extern FILE *Pel_In; extern char *Pel_LogName; extern char *FilePrefix; extern int Cont_Alg; extern int Show_Sys; extern int Show_Xpl;#endif/**************************************************************************//************************ declarations from Rand.h ************************//**************************************************************************/void rand_seed(long int seedval);int rand_int(int low, int high);double rand_double(int low, int high);double drand48();void srand48(long int seedval);/**************************************************************************//************************ definitions from Dlist.h ************************//**************************************************************************//*** Define a list type for safe protection from garbage collection. **** L is assumed to be a safe local node variable for the procedure** main(); After initialization (with Dlist_new())** a doubly linked list of nodes is maintained with two operations:**** Dlist_add(L,data) --- crates an entree to hold the node data in** L, inserted at the front of the list, and** returns the pointer to the list entry.** Dlist_rem(L,node) --- takes a pointer to a list entry unlinks ** it from the list L and returns the ** original data node.** Dlist_data(node) -- takes a list entry and returns the ** original data node.****** DList Header | Dlist Node |** | |** ____________ | ------------- |** |Node | Node | | | Node | Node | next |** | 0 | ----+----->| | | | -----+--------> |** ------------ first | ---+--------- |** | | !** | |link |** | _____________ |** | | Node | Node | |** | +--- | | | |** | ----------+-- |** | |data |** | | |*/#define Dnode_link(D) (((node)(D))->L.ptr)#define Dnode_next(D) (((node)D)->R.ptr)#define Dnode_prev(D) (((node)Dnode_link((node)(D)))->L.ptr)#define Dnode_data(D) (((node)Dnode_link((node)(D)))->R.ptr)#define Dlist_new() new_node()#define Dlist_first(L) Dnode_next(L)void Dlist_empty(node L);/*** invariants: Dnode_next(Dnode_prev(pos)) ==pos ** for all pointers to Dlist node entrees.** (NOTE: Dnode_next(L) := Dlist_first(L), ** where L is list header) **** Dnode_prev(Dnode_next(pos))=pos** for all non-zero pointers to Dlist node entrees ** and also for list header** */node Dlist_add(node L, node data);node Dlist_del(node L, node pos);node Dlist_data(node pos);/**************************************************************************//********************** declarations from Dmatrix.h ***********************//**************************************************************************/ typedef struct Dmatrix_t *Dmatrix; typedef struct Dmatrix_t *Dvector; #ifdef DMATRIX_FAST struct Dmatrix_t { int store; int nrows; int ncols; double *coords; }; #define DVstore(V) (((V)->store)) #define DVlength(V) (((V)->ncols)) #define DVref1(V,j) (((V)->coords)[(j)-1]) #define DVref0(V,j) (((V)->coords)[j]) #define DVref(V,i) DVref1(V,i) #define DMstore(V) (((V)->store)) #define DMMrows(V) (((V)->store/(V)->ncols)) #define DMrows(V) ((V)->nrows) #define DMcols(V) ((V)->ncols) #define DMelts(V) ((V)->coords) #define DMref1(V,i,j) (((V)->coords)[((i)-1)*DMcols(V)+(j)-1]) #define DMref0(V,i,j) (((V)->coords)[(i)*DMcols(V)+(j)]) #define DMref(V,i,j) DMref1((V),i,j) #else /* ** matrix access macroes */ double DMstore(Dmatrix M); /* maximum #elts available*/ double DMMrows(Dmatrix M); /* maximum #rows */ double DMrows(Dmatrix M); /* number rows stored */ double DMcols(Dmatrix M); /* number cols stored */ double *DMref_P(Dmatrix M,int i,int j); /* acces starting at 1*/ double *DMelts(Dmatrix M); /* acces starting at 1*/ #define DMref0(M,i,j) (*DMref_P(M,i,j)) #define DMref1(M,i,j) (*DMref_P(M,(i)-1,(j)-1)) #define DMref(M,i,j) DMref1(M,i,j) /* ** Vectors are implemented as 1xM matrices, and acces is through ** usual matrix functions via macroes */ #define DVstore(V) (DMstore(V)) /* maximum #elts available */ #define DVlength(V) (DMcols(V)) /* actual #elts stored */ #define DVref1(V,i) (DMref1(V,1,i)) /* acces ith elt (starting at 1)*/ #define DVref0(V,i) (DMref0(V,0,i)) /* acces ith elt (starting at 0)*/ #define DVref(V,i) (DVref1(V,i)) #endif /*** Constructor/Destructors/Display*/Dmatrix Dmatrix_new(int r, int c);Dmatrix Dmatrix_resize(Dmatrix M, int r, int d);void Dmatrix_free(Dmatrix V);Dmatrix Dmatrix_fprint(FILE *fout,Dmatrix M);#define Dmatrix_print(M) (Dmatrix_fprint(stdout,M))#define Dvector_print(V) (Dmatrix_fprint(stdout,V))#define Dvector_fprint(F,V) (Dmatrix_fprint(F,V))#define Dvector_new(n) (Dmatrix_new(1,n))#define Dvector_free(V) (Dmatrix_free(V))/*** Arithmatic and other operations on Dmatrices*/Dmatrix Dmatrix_add(Dmatrix M1, Dmatrix M2, Dmatrix *M3);#define add_Dvector(V1,V2,V3) add_Dmatrix(V1,V2,V3)Dmatrix Dmatrix_mull(Dmatrix M1, Dmatrix M2, Dmatrix *M3); Dmatrix Dmatrix_dot(Dmatrix M1, Dmatrix M2, Dmatrix M3); int Dvector_dot(Dmatrix M1, Dmatrix M2);int equal_Dmatrix(Dmatrix M1,Dmatrix M2);void Dmatrix_GQR(Dmatrix,Dmatrix);void Dmatrix_Solve(Dmatrix,Dmatrix,int);/* end Dmatrix.h *//**************************************************************************//********************** declarations from Imatrix.h ***********************//**************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -