source: trunk/optimizer/src/rp_optimizer.h @ 898

Last change on this file since 898 was 898, checked in by mmc, 15 years ago

Optimization part is getting better. Fleshed out the plug-in for
PGApack, and integrated a first cut that includes the data handling.

File size: 4.4 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
26/*
27 * General-purpose allocation/cleanup routines:
28 * These are used, for example, for the plug-in architecture.
29 */
30typedef ClientData (RpOptimInit)_ANSI_ARGS_(());
31typedef void (RpOptimCleanup)_ANSI_ARGS_((ClientData cdata));
32
33/*
34 * During each optimization, a function of the following type is
35 * called again and again to evaluate input parameters and compute
36 * the fitness function.
37 */
38typedef enum {
39    RP_OPTIM_SUCCESS=0, RP_OPTIM_UNKNOWN, RP_OPTIM_FAILURE, RP_OPTIM_ABORTED
40} RpOptimStatus;
41
42struct RpOptimEnv;   /* defined below */
43struct RpOptimParam;
44
45typedef RpOptimStatus (RpOptimEvaluator) _ANSI_ARGS_((
46    struct RpOptimEnv *envPtr, struct RpOptimParam *values, int numValues,
47    double *fitnessPtr));
48
49typedef RpOptimStatus (RpOptimHandler) _ANSI_ARGS_((
50    struct RpOptimEnv *envPtr, RpOptimEvaluator *evalProc));
51
52/*
53 * This is the basic definition for each parameter within an optimization.
54 * Each parameter has a name, type, and value.  The value is important
55 * at the end of an optimization.  It is either the final value, or the
56 * value where we left off when the optimization was terminated.
57 */
58typedef enum {
59    RP_OPTIMPARAM_NUMBER, RP_OPTIMPARAM_STRING
60} RpOptimParamType;
61
62typedef struct RpDiscreteString {
63    int num;                        /* integer representing this string */
64    char *str;                      /* actual string selected */
65} RpDiscreteString;
66
67typedef struct RpOptimParam {
68    char *name;                     /* name of this parameter */
69    RpOptimParamType type;          /* paramter type -- number, string, etc */
70    union {
71        double dval;                /* slot for number value */
72        int ival;                   /* slot for integer value */
73        RpDiscreteString sval;      /* slot for string value */
74    } value;
75} RpOptimParam;
76
77/*
78 * NUMBER PARAMETERS have additional min/max values as constraints.
79 */
80typedef struct RpOptimParamNumber {
81    RpOptimParam base;              /* basic parameter info */
82    double min;                     /* optimization constraint: min value */
83    double max;                     /* optimization constraint: max value */
84} RpOptimParamNumber;
85
86/*
87 * STRING PARAMETERS have a set of allowed values.
88 */
89typedef struct RpOptimParamString {
90    RpOptimParam base;              /* basic parameter info */
91    char **values;                  /* array of allowed values */
92    int numValues;                  /* number of allowed values */
93} RpOptimParamString;
94
95/*
96 * Each optimization problem is represented by a context that includes
97 * the parameters that will be varied.
98 */
99typedef struct RpOptimEnv {
100    RpOptimEvaluator *evalProc;     /* called during optimization to do run */
101    ClientData pluginData;          /* data created by plugin init routine */
102    RpOptimCleanup *cleanupProc;    /* cleanup routine for pluginData */
103    ClientData toolData;            /* data used during tool execution */
104    RpOptimParam **paramList;       /* list of input parameters to vary */
105    int numParams;                  /* current number of parameters */
106    int maxParams;                  /* storage for this many paramters */
107} RpOptimEnv;
108
109/*
110 *  Here are the functions in the API:
111 */
112EXTERN RpOptimEnv* RpOptimCreate _ANSI_ARGS_((ClientData pluginData,
113    RpOptimCleanup *cleanupProc));
114
115EXTERN RpOptimParam* RpOptimAddParamNumber _ANSI_ARGS_((RpOptimEnv *envPtr,
116    char *name));
117
118EXTERN RpOptimParam* RpOptimAddParamString _ANSI_ARGS_((RpOptimEnv *envPtr,
119    char *name));
120
121EXTERN RpOptimParam* RpOptimFindParam _ANSI_ARGS_((RpOptimEnv *envPtr,
122    char *name));
123
124EXTERN void RpOptimDeleteParam _ANSI_ARGS_((RpOptimEnv *envPtr, char *name));
125
126EXTERN void RpOptimDelete _ANSI_ARGS_((RpOptimEnv *envPtr));
127
128#endif
Note: See TracBrowser for help on using the repository browser.