source: trunk/packages/optimizer/src/rp_optimizer.h @ 1062

Last change on this file since 1062 was 1062, checked in by liveletlive, 14 years ago

Committing changes related to command <name> samples ?number?

File size: 5.2 KB
Line 
1/*
2 * ----------------------------------------------------------------------
3 *  rp_optimizer
4 *
5 *  This is the C language API for the optimization package in
6 *  Rappture.  It lets you set up an optimization of some fitness
7 *  function with respect to a set of inputs.
8 *
9 * ======================================================================
10 *  AUTHOR:  Michael McLennan, Purdue University
11 *  Copyright (c) 2008  Purdue Research Foundation
12 *
13 *  See the file "license.terms" for information on usage and
14 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
15 * ======================================================================
16 */
17#ifndef RP_OPTIMIZER
18#define RP_OPTIMIZER
19
20#include <tcl.h>
21#include <math.h>
22#include <float.h>
23#include <string.h>
24#include <malloc.h>
25#include "rp_tcloptions.h"
26
27#define PGAPACK_RUNTIME_TABLE_DEFAULT_SIZE 5000 /*Approx Number of Samples in a run*/
28#define SINGLE_SAMPLE_DATA_BUFFER_DEFAULT_SIZE 5000
29
30/*
31 * General-purpose allocation/cleanup routines:
32 * These are used, for example, for the plug-in architecture.
33 */
34typedef ClientData (RpOptimInit)_ANSI_ARGS_(());
35typedef void (RpOptimCleanup)_ANSI_ARGS_((ClientData cdata));
36
37/*
38 * During each optimization, a function of the following type is
39 * called again and again to evaluate input parameters and compute
40 * the fitness function.
41 */
42typedef enum {
43    RP_OPTIM_SUCCESS=0, RP_OPTIM_UNKNOWN, RP_OPTIM_FAILURE, RP_OPTIM_ABORTED
44} RpOptimStatus;
45
46struct RpOptimEnv;   /* defined below */
47struct RpOptimParam;
48
49typedef RpOptimStatus (RpOptimEvaluator) _ANSI_ARGS_((
50    struct RpOptimEnv *envPtr, struct RpOptimParam *values, int numValues,
51    double *fitnessPtr));
52
53typedef RpOptimStatus (RpOptimHandler) _ANSI_ARGS_((
54    struct RpOptimEnv *envPtr, RpOptimEvaluator *evalProc,
55    char *fitnessExpr));
56
57/*
58 * Each optimization package is plugged in to this infrastructure
59 * by defining the following data at the top of rp_optimizer_tcl.c
60 */
61typedef struct RpOptimPlugin {
62    char *name;                   /* name of this package for -using */
63    RpOptimInit *initProc;        /* initialization routine */
64    RpOptimHandler *runProc;      /* handles the core optimization */
65    RpOptimCleanup *cleanupProc;  /* cleanup routine */
66    RpTclOption *optionSpec;      /* specs for config options */
67} RpOptimPlugin;
68
69/*
70 * This is the basic definition for each parameter within an optimization.
71 * Each parameter has a name, type, and value.  The value is important
72 * at the end of an optimization.  It is either the final value, or the
73 * value where we left off when the optimization was terminated.
74 */
75typedef enum {
76    RP_OPTIMPARAM_NUMBER, RP_OPTIMPARAM_STRING
77} RpOptimParamType;
78
79typedef struct RpDiscreteString {
80    int num;                        /* integer representing this string */
81    char *str;                      /* actual string selected */
82} RpDiscreteString;
83
84typedef struct RpOptimParam {
85    char *name;                     /* name of this parameter */
86    RpOptimParamType type;          /* paramter type -- number, string, etc */
87    union {
88        double dval;                /* slot for number value */
89        int ival;                   /* slot for integer value */
90        RpDiscreteString sval;      /* slot for string value */
91    } value;
92} RpOptimParam;
93
94/*
95 * NUMBER PARAMETERS have additional min/max values as constraints.
96 */
97typedef struct RpOptimParamNumber {
98    RpOptimParam base;              /* basic parameter info */
99    double min;                     /* optimization constraint: min value */
100    double max;                     /* optimization constraint: max value */
101} RpOptimParamNumber;
102
103/*
104 * STRING PARAMETERS have a set of allowed values.
105 */
106typedef struct RpOptimParamString {
107    RpOptimParam base;              /* basic parameter info */
108    char **values;                  /* array of allowed values */
109    int numValues;                  /* number of allowed values */
110} RpOptimParamString;
111
112/*
113 * Each optimization problem is represented by a context that includes
114 * the parameters that will be varied.
115 */
116typedef struct RpOptimEnv {
117    RpOptimPlugin *pluginDefn;      /* plug-in handling this optimization */
118    ClientData pluginData;          /* data created by plugin init routine */
119    RpOptimEvaluator *evalProc;     /* called during optimization to do run */
120    char *fitnessExpr;              /* fitness function in string form */
121    ClientData toolData;            /* data used during tool execution */
122    RpOptimParam **paramList;       /* list of input parameters to vary */
123    int numParams;                  /* current number of parameters */
124    int maxParams;                  /* storage for this many paramters */
125} RpOptimEnv;
126
127/*
128 *  Here are the functions in the API:
129 */
130EXTERN RpOptimEnv* RpOptimCreate _ANSI_ARGS_((RpOptimPlugin *pluginDefn));
131
132EXTERN RpOptimParam* RpOptimAddParamNumber _ANSI_ARGS_((RpOptimEnv *envPtr,
133    char *name));
134
135EXTERN RpOptimParam* RpOptimAddParamString _ANSI_ARGS_((RpOptimEnv *envPtr,
136    char *name));
137
138EXTERN RpOptimParam* RpOptimFindParam _ANSI_ARGS_((RpOptimEnv *envPtr,
139    char *name));
140
141EXTERN void RpOptimDeleteParam _ANSI_ARGS_((RpOptimEnv *envPtr, char *name));
142
143EXTERN void RpOptimDelete _ANSI_ARGS_((RpOptimEnv *envPtr));
144
145
146#endif
Note: See TracBrowser for help on using the repository browser.