Hello,

I am new to ALGLIB and I must say it is a great library to use.

My issue is that I have the following optimization problem (c#), and I am trying to obtain the most evenly distributed solution, i.e. I'm aiming to have a reduction in the weights that is as evenly distributed amongst them as possible. Is there a way to ensure that? My code is as follows:

**Code:**

public static void createWeightsFunction(double[] w, ref double func, double[] grad, object obj)

{

//Create the function to minimise

//In our case: - w[0] - w[1] - ... - w[n-1]

func = 0;

for (int i = 0; i < w.Length; i++)

{

func -= w[i];

grad[i] = 1;

}

}

public static double[] getOptimizedWeights(double[] totalAppliancePrices, double[] thresholds, double target)

{

double[] weights = new double[totalAppliancePrices.Length];

for (int i = 0; i < weights.Length; i++)

{

weights[i] = 1;

}

double[,] constr = new double[1, weights.Length + 1];

//Add total consumption condition

for (int i = 0; i < weights.Length; i++)

{

constr[0, i] = totalAppliancePrices[i];

}

constr[0, weights.Length] = target;

int[] ct = new int[1];

ct[0] = 0;

// Add boundary constraints

double[] bndl = new double[weights.Length];

double[] bndu = new double[weights.Length];

for (int i = 0; i < weights.Length; i++)

{

bndl[i] = thresholds[i];

bndu[i] = 1;

}

alglib.minbleicstate state;

alglib.minbleicreport rep;

//

// These variables define stopping conditions for the optimizer.

//

// We use very simple condition - |g|<=epsg

//

double epsg = 0.000001;

double epsf = 0;

double epsx = 0;

int maxits = 0;

//

// Now we are ready to actually optimize something:

// * first we create optimizer

// * we add linear constraint

// * we add the boundary constraints

// * we tune stopping conditions

// * and, finally, optimize and obtain results...

//

try

{

alglib.minbleiccreate(weights, out state);

alglib.minbleicsetlc(state, constr, ct);

alglib.minbleicsetbc(state, bndl, bndu);

alglib.minbleicsetcond(state, epsg, epsf, epsx, maxits);

alglib.minbleicoptimize(state, createWeightsFunction, null, null);

alglib.minbleicresults(state, out weights, out rep);

}

catch (Exception ex)

{

}

return weights;

}

Thank you in advance.