Institut de Robòtica i Informàtica Industrial
KRD Group

The CuikSuite Project

cuiksystem.h

Go to the documentation of this file.
00001 #ifndef CUIKSYSTEMH
00002 #define CUIKSYSTEMH
00003 
00004 #include "equations.h"
00005 #include "variables.h"
00006 #include "statistics.h"
00007 #include "list.h"
00008 #include "box_list.h"
00009 #include "parameters.h"
00010 #include "box.h"
00011 #include "boolean.h"
00012 #include "vector.h"
00013 #include "csmapping.h"
00014 
00015 #include <stdlib.h>
00016 
00017 
00026 /************************************************************************************/
00032 #define DEPTH_FIRST_SEARCH 1
00033 /************************************************************************************/
00034 
00035 /************************************************************************************/
00041 #define BREADTH_FIRST_SEARCH 2
00042 /************************************************************************************/
00043 
00044 /************************************************************************************/
00054 #define MINIMIZATION_SEARCH 3
00055 /************************************************************************************/
00056 
00057 /************************************************************************************/
00065 /*#define CUT_POINT 0.5*/
00066 #define CUT_POINT 0.45+0.1*randomDouble()
00067 /************************************************************************************/
00068 
00069 /************************************************************************************/
00075 #define MPI_TREAT_BOX_TIMEOUT(cs) (cs->nvariables*SIMPLEX_TIMEOUT*10)
00076 /************************************************************************************/
00077 
00098 typedef struct { 
00099   boolean updated; 
00100   boolean empty;   
00102   Tstatistics st; 
00104   Tmapping *simplification; 
00106   /*  */
00107   unsigned int searchMode; 
00108   Tequation orig_eqMin; 
00110   Tequation eqMin; 
00113   /******************************************************************************/
00114   /* SIMPLIFIED AND DUMMIFIED SUB-SYTEM                                         */
00115   Tmapping *orig2sd; 
00117   Tequations equations; 
00118   Tvariables variables; 
00120   unsigned int nequations; 
00121   unsigned int nvariables; 
00122   boolean *systemVar; 
00123   boolean *notDummyVar; 
00124   unsigned int *varType; 
00126   /******************************************************************************/
00127   /* SIMPLIFIED SUB-SYTEM                                                       */
00128   Tmapping *orig2s; 
00130   Tequations simp_equations; 
00131   Tvariables simp_variables; 
00133   unsigned int simp_nequations; 
00134   unsigned int simp_nvariables; 
00135   unsigned int simp_nee; 
00136   Tequation **J; 
00139   /******************************************************************************/
00140   /* ORIGINAL SUB-SYTEM                                                         */
00141   Tequations orig_equations; 
00142   Tvariables orig_variables; 
00144   unsigned int orig_nequations;
00145   unsigned int orig_nvariables;
00146   boolean *orig_systemVar; 
00147   boolean *orig_notDummyVar;
00149   char **orig_varNames; 
00151 } TCuikSystem;
00152 
00153 
00154 /****************************************************************************/
00155 /* Methods to initialize/define/re-define CuikSystems (constructors et al.) */
00156 /****************************************************************************/
00157 
00165 void InitCuikSystem(TCuikSystem *cs);
00166 
00167 
00181 void InitCuikSystemFromFile(Tparameters *p,char *filename,TCuikSystem *cs);
00182 
00191 void CopyCuikSystem(TCuikSystem *cs_dst,TCuikSystem *cs_src);
00192 
00209 void CuikSystemMerge(Tparameters *p,TCuikSystem *cs1,TCuikSystem *cs2,TCuikSystem *cs);
00210 
00211 
00231 boolean CmpBoxesEquation(void *b1,void *b2,void *cs);
00232 
00250 void SetCSSearchMode(unsigned int sm,Tequation *eqMin,TCuikSystem *cs);
00251 
00270 void AddTerm2SearchCriterion(double w,unsigned int v,double val,TCuikSystem *cs);
00271 
00272 /****************************************************************************/
00273 /*     Methods to add individual variables/equations to the cuik system     */
00274 /****************************************************************************/
00275 
00288 unsigned int AddVariable2CS(Tvariable *v,TCuikSystem *cs);
00289 
00300 void AddEquation2CS(Tparameters *p,Tequation *eq,TCuikSystem *cs);
00301 
00302 
00303 /****************************************************************************/
00304 /*        Methods to access the data stored in the CuikSystem.              */
00305 /*  These methods provide controlled access to the stored data so that the  */
00306 /*     higher levels can not introduce inconsistancies in the CuikSystem    */
00307 /****************************************************************************/
00308 
00321 void GetCSVariables(Tvariables *vs,TCuikSystem *cs);
00322 
00332 unsigned int GetCSNumVariables(TCuikSystem *cs);
00333 
00344 unsigned int GetCSNumNonDummyVariables(TCuikSystem *cs);
00345 
00346 
00360 void GetCSVariable(unsigned int n,Tvariable *v,TCuikSystem *cs);
00361 
00375 void SetCSVariableRange(unsigned int n,Tinterval *r,TCuikSystem *cs);
00376 
00388 unsigned int GetCSVariableID(char *name,TCuikSystem *cs);
00389 
00401 unsigned int GetCSSystemVars(boolean **sv,TCuikSystem *cs);
00402 
00414 void GetCSEquations(Tequations *eqs,TCuikSystem *cs);
00415 
00425 unsigned int GetCSNumEquations(TCuikSystem *cs);
00426 
00439 void GetCSEquation(unsigned int n,Tequation *eq,TCuikSystem *cs);
00440 
00458 void GetCuikSystemJacobian(Tequation ***J,TCuikSystem *cs);
00459 
00468 void DeleteCuikSystemJacobian(Tequation **J,TCuikSystem *cs);
00469 
00470 /****************************************************************************/
00471 /*                    Methods to solve the CuikSystem.                      */
00472 /****************************************************************************/
00473 
00489 unsigned int MaxReduction(Tparameters *p,unsigned int varMask,Tbox *b,TCuikSystem *cs);
00490 
00534 boolean SampleCuikSystem(Tparameters *p,char *fname,Tlist *sb,
00535                          unsigned int nsamples,unsigned int ntries,
00536                          unsigned int ndof,TCuikSystem *cs);
00537 
00568 boolean SampleCuikSystemInBox(Tparameters *p,char *fname,Tlist *sb,
00569                               unsigned int nsamples,unsigned int ntries,
00570                               unsigned int ndof,
00571                               Tbox *init_box,TCuikSystem *cs);
00572 
00606 void SolveCuikSystem(Tparameters *p,unsigned int nsols,
00607                      boolean restart,char *fstate,
00608                      FILE *f_out,Tlist *sol,TCuikSystem *cs);
00609 
00610 #if (_USE_MPI)
00611 
00635   void MPI_SolveCuikSystem(Tparameters *p,
00636                            boolean restart,char *fstate,
00637                            FILE *f_out,TCuikSystem *cs);
00649   void MPI_TreatBox(Tparameters *p,TCuikSystem *cs);
00650 #endif
00651 
00652 
00653 /****************************************************************************/
00654 /*                           Auxiliary Methods.                             */
00655 /****************************************************************************/
00667 void GenerateInitialBox(Tbox *box,TCuikSystem *cs);
00668 
00691 void ReGenerateOriginalBox(Tparameters *p,Tbox *boxS,Tbox *boxO,TCuikSystem *cs);
00692 
00706 unsigned int ComputeSplitDim(Tparameters *p,Tbox *b,TCuikSystem *cs);
00707 
00726 boolean PointInSystemBox(Tvector *v,Tbox *b,TCuikSystem *cs);
00727 
00743 double ErrorInSolution(Tbox *b,TCuikSystem *cs);
00744 
00762 double ErrorInInequalities(Tbox *b,TCuikSystem *cs);
00763 
00782 boolean CoordInequalitiesHold(Tbox *b,TCuikSystem *cs);
00783 
00784 /****************************************************************************/
00785 /*               Output the information in the CuikSystem                   */
00786 /****************************************************************************/
00787 
00797 void PrintCuikSystem(Tparameters *p,FILE *f,TCuikSystem *cs);
00798 
00813 void PrintCuikSystemWithSimplification(Tparameters *p,FILE *f,TCuikSystem *cs);
00814 
00815 
00825 void SaveCuikSystemSimplification(Tparameters *p,FILE *f,TCuikSystem *cs);
00826 
00827 
00828 /****************************************************************************/
00829 /*                                 Destructor                               */
00830 /****************************************************************************/
00831 
00839 void DeleteCuikSystem(TCuikSystem *cs);
00840 
00841 #endif