source: branches/uq/packages/optimizer/src/pgapack/pgapack/examples/c/sampleOptimization.c @ 5679

Last change on this file since 5679 was 5679, checked in by ldelgass, 9 years ago

Full merge 1.3 branch to uq branch to sync. Fixed partial subdirectory merge
by removing mergeinfo from lang/python/Rappture directory.

  • Property svn:eol-style set to native
File size: 2.3 KB
Line 
1/*
2 * Ganesh Hegde: GENES Learning
3 * This is a sample optimization written for simple parameter values
4 * The aim is to fit a given I-V for a MOSFET
5 * The variables that are entering into the optimization problem are Vgs - Gate to Source Voltage and W/L-
6 * The Width of the oxide layer divided by its length
7 * using given Vgs -- 2V and W/L == 10, an I-V is obtained and fet as the function to be optimized
8 *
9 */
10 
11#include <pgapack.h>
12#include <stdlib.h>
13
14double evaluationFunction(PGAContext *, int, int);
15
16
17int main(int argc, char **argv){
18        PGAContext *ctx;
19        int strLen;
20        double low[]={1.5,5} ,high[]={5,12.0};
21
22    ctx = PGACreate(&argc, argv, PGA_DATATYPE_REAL, 2, PGA_MINIMIZE);
23    PGASetRealInitRange(ctx,low,high);
24    PGASetPopSize(ctx,1000);
25    PGASetCrossoverType(ctx,PGA_CROSSOVER_ONEPT);
26    PGASetRandomSeed(ctx, 1);
27    PGASetStoppingRuleType(ctx, PGA_STOP_NOCHANGE);
28    PGASetUp(ctx);
29    PGARun(ctx, evaluationFunction);
30    PGADestroy(ctx);
31        return 0;
32}
33
34/*
35 * Sample Evaluation function for evaluating the parameters returned by the PGARun function on one cycle
36 * ctx--> context variable
37 * index--> chromosome index in the population
38 * populationNumber --> Which population to look at
39 */
40
41double evaluationFunction(PGAContext *ctx, int index, int populationNumber){
42        int i, stringLen;
43        double realAllele,vGS=0.0,widthToLengthRatio=0.0;
44        double Vds[21]={0}, Ids[21]={0};
45        double mu = 300 ;/*In cm^2/V-s*/
46        int Vt=1,j=0;
47        double tox= 20e-7;
48        double Cox= (3.9*8.85e-14)/tox;
49        double k,slope,targetslope,fitness=0;
50        double targetIds[] = {0,0.0005,0.0010,0.0016,0.0021,0.0026,0.0031,0.0036,0.0041,0.0047,0.0052,0.0057,0.0062,0.0067,0.0072,0.0078,0.0083,0.0088,0.0093,0.0098,0.0104};
51        stringLen = PGAGetStringLength(ctx);
52        for(i=0;i<stringLen;i++){
53                realAllele = PGAGetRealAllele(ctx, index, populationNumber, i);
54                if(i==0){
55                        vGS=realAllele;
56                }else{
57                        widthToLengthRatio = realAllele;
58                }
59               
60        }
61        /*
62         * Initing the Vds array
63         */
64        k=mu*Cox*widthToLengthRatio;
65       
66        for(i=0;i<21;i++){
67                if(i>0){
68                Vds[i]=Vds[i-1]+0.5;
69                }else{
70                        Vds[i]=0;
71                }               
72                Ids[i]=k*((vGS-Vt)*Vds[i]);
73        }
74        slope = (Ids[20]-Ids[0])/(Vds[20]-Vds[0]);
75        targetslope = (targetIds[20]-targetIds[0])/(Vds[20]-Vds[0]);
76        for(j=0;j<21;j++){
77//              printf("%lf ",Ids[j]);
78        }
79        return (double)abs(slope-targetslope);
80       
81}
Note: See TracBrowser for help on using the repository browser.