// this function draws the spectrogram of benchmark function and the constraint curves
void Plot::drawNewData(){
this->detachItems();
// load the corresponding struct with optimization problem
//
optProbList = _mf->getOptProblems();
unsigned index= _mf->objFunction;
double (*f)(vector<double> coord) = optProbList[index]->benchmark;
double rangex1[2] = {optProbList[index]->min[_mf->dim_indices[0]], optProbList[index]->max[_mf->dim_indices[0]]};
double rangex2[2] = {optProbList[index]->min[_mf->dim_indices[1]], optProbList[index]->max[_mf->dim_indices[1]]};
// here the data for ploting is set from the function "SpectrogramData()", in which the data is generated
//
d_spectrogram->setData(SpectrogramData((*f), rangex1, rangex2, _mf->dim_indices , _mf->fixed_values, optProbList[index]->dimensions, value_interval));
d_spectrogram->attach(this); // attach the data to the plot widget
// set the colors for intensity values
//
colorMap.addColorStop(0.25, Qt::cyan);
colorMap.addColorStop(0.5, Qt::green);
colorMap.addColorStop(0.75, Qt::yellow);
d_spectrogram->setColorMap(colorMap);
// A color bar on the right axis
//
rightAxis->setTitle("Intensity");
rightAxis->setColorBarEnabled(true);
rightAxis->setColorMap(d_spectrogram->data().range(), d_spectrogram->colorMap());
// set the scale of color bar
//
d_spectrogram->data().range().minValue(),
d_spectrogram->data().range().maxValue() );
// define the steps and number of contour lines
//
QwtValueList contourLevels;
double stepsize;
if(value_interval.width()<2){
stepsize = 0.2;
}
if(value_interval.width()>=5 && value_interval.width() < 20){
stepsize = 1;
}
if(value_interval.width()>=20 && value_interval.width() < 50){
stepsize = 5;
}
if (value_interval.width() >= 50 && value_interval.width() < 1000){
stepsize = 50;
}
if ( value_interval.width() >= 1000){
stepsize = 10000;
}
for ( double level = value_interval.minValue(); level < value_interval.maxValue(); level += stepsize )
contourLevels += level;
d_spectrogram->setContourLevels(contourLevels);
plotLayout()->setAlignCanvasToScales(true);
//+++++++++++++++++ plot constraints curves if the option "use constraints" is selected ++++++++++++++++++++++
if(_mf->useConstraints){ // if the user has checked the radio button "use constraints" in initialization...
QVector<int> equality = optProbList[index]->constraint_equality;
if(_mf->allConstraints){ // if use all constraints
int k=0;
for( std::map<QString, double (*)( vector<double> )>::iterator ii = optProbList[index]->constraints.begin(); ii!= optProbList[index]->constraints.end(); ++ii)
{
double step_size = 0.5 ;
for(double x1= optProbList[index]->min[_mf->dim_indices[0]] ; x1 < optProbList[index]->max[_mf->dim_indices[0]] ; x1=x1+ step_size){
for(double x2= optProbList[index]->min[_mf->dim_indices[1]] ; x2 < optProbList[index]->max[_mf->dim_indices[1]] ; x2=x2+ step_size){
vector<double> coords(3,0);
coords = _mf->fixed_values;
coords[_mf->dim_indices[0]] = x1;
coords[_mf->dim_indices[1]] = x2;
double result = (*ii).second(coords); // compute the y value
if(result==1){
// create PlotMarkers to visualize the infeasible area
symb
->setBrush
(QBrush(Qt
::red, Qt
::SolidPattern));
symb->setSize(5,5);
mark->setSymbol(*symb);
mark->setXValue(x1); // set the position of marker on the plot
mark->setYValue(x2);
//mark->setZ(101);
mark->attach(this);
}
}
}
k= k+1;
}
}
else{ // if use certain constraint
unsigned t = 0;
for( std::map<QString, double(*)( vector<double> )>::iterator ii = optProbList[index]->constraints.begin(); ii!= optProbList[index]->constraints.end(); ++ii)
{
if(t== _mf->constraint){
double step_size = 0.5 ;
for(double x1= optProbList[index]->min[_mf->dim_indices[0]] ; x1 < optProbList[index]->max[_mf->dim_indices[0]] ; x1=x1+ step_size){
for(double x2= optProbList[index]->min[_mf->dim_indices[1]] ; x2 < optProbList[index]->max[_mf->dim_indices[1]] ; x2=x2+ step_size){
vector<double> coords(3,0);
coords = _mf->fixed_values;
coords[_mf->dim_indices[0]] = x1;
coords[_mf->dim_indices[1]] = x2;
double result = (*ii).second(coords); // compute the y value
if(result==1){
// create PlotMarkers to visualize the infeasible area
symb
->setBrush
(QBrush(Qt
::red, Qt
::SolidPattern));
symb->setSize(5,5);
mark->setSymbol(*symb);
mark->setXValue(x1); // set the position of marker on the plot
mark->setYValue(x2);
//mark->setZ(101);
mark->attach(this);
}
}
}
}
t= t+1;
}
}
}
//+++++++++++++++++ end of plot constraints curves if the option "use constraints" is selected ++++++++++++++++++++++
replot();
}
Bookmarks