lbl-srg / GenOpt

GenOpt - Generic Optimization program
http://simulationresearch.lbl.gov/GO
20 stars 14 forks source link

Bug if only discrete parameters are present #2

Closed mwetter closed 8 years ago

mwetter commented 8 years ago

A user reports: There is a bug resulting in an error when there are only discrete variables and no continuous ones in the optimization problem. It is in the Optimizer class, lines 883-892.

            for (int i=0; i < dimCon-1; i++)
                em += x[iT].getX(i) + ", ";
            if (dimDis == 0)
            em += x[iT].getX(dimCon-1) + ")." + LS;
            else{
            em += x[iT].getX(dimCon-1) + "; ";
            for (int i=0; i < dimDis-1; i++)
                em += x[iT].getIndex(i) + ", ";
            em += x[iT].getIndex(dimDis-1) + ")." + LS;
            }

I managed to amend it by using the following code in its place

for (int i=0; i < dimCon-1; i++)
                em += x[iT].getX(i) + ", ";
for (int i=0; i < dimDis-1; i++)
                em += x[iT].getIndex(i) + ", ";
            if (dimDis == 0)
            em += x[iT].getX(dimCon-1) + ")." + LS;
                    else if (dimCon == 0){
                        em += x[iT].getIndex(dimDis-1) + ")." + LS;            
            }else{
                        em += x[iT].getX(dimCon-1) + ", " + x[iT].getIndex(dimDis-1) + ")." + LS;
                    }

This needs to be

mwetter commented 8 years ago

This is now on the master