现在在做个复合形优化设计程序,其中要用到随机函数产生随机顶点;
约束条件s.t.
50-30/(X1*X2*X2)>=0;
0.001-0.0004X1*X2>=0;
2>=X1<=4;
0.5>=X2<=1;
现在想在可行区内找到随机顶点;为什么用下列程序,得到的随机顶点时0,而这个顶点明显不在可行域内;
#include<math.h>
#include<stdio.h>
#include<stdlib.h>
#define n 2
#define k 4
int i,j;
double X0[n],XX[n],X[k][n],rr[n];
void produce(double A[n],double B[n]);                                 
double a[n],b[n];
int cons(double D[n]);                                               
void bou();
void main()
{
        produce;
        for(i=0;i<n;i++)
        {        
                printf("%f\n",XX[i]);
        printf("%i\n",rr[i]);
        }
    printf("Random numbers are: %f %f\n",rand(),rand());
}

int cons(double D[n])
{
        if(((30/(D[0]*D[1]*D[1])-50)<=0)&&((0.0004*D[0]*D[1]-0.001)<=0)&&
                ((D[0]>=2)&&(D[0]<=4))&&((D[1]>=0.5)&&(D[1]<=1)))               
                return 1;
        else
                return 0;
}
void bou()                                                              
{
        a[0]=2;
        a[1]=0.5;
        b[0]=4;
        b[1]=1;
}
void produce(double A[n],double B[n])
{
        do
        {
                rr[n]=rand();
                rr[n]=rr[n]/3659;
                for(i=0;i<n;i++)
                {
                        X[0][i]=A[i]+rr[n]*(B[i]-A[i]);
                        XX[i]=X[0][i];
                }
        }
        while(cons(XX)==0);
}