You are on page 1of 6

Unconstraint Optimization

Java code

package optimization;

import java.io.DataOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;

public class Unconstrained {

private ArrayList<Double> vOld;


private ArrayList<Double> vNew;
private Double lambda;

public Unconstrained(ArrayList<Double> vOld, ArrayList<Double> vNew, Double


lambda) {
this.vOld = vOld;
this.vNew = vNew;
this.lambda = lambda;
}

public void derivaties() {


Double x1 = vOld.get(0);
Double x2 = vOld.get(1);
Double deltaX1 = 1 + 10 * x1 - 4 * x2;
Double deltaX2 = -1 + 4 * x1 + 10 * x2;
this.vNew.set(0, x1 - this.lambda * deltaX1);
this.vNew.set(1, x2 - this.lambda * deltaX2);
}

public double distanceEuclidienne(ArrayList<Double> vOld, ArrayList<Double>


vNew) {
Double sum = 0.0;
for (int i = 0; i < vOld.size(); i++) {
sum = sum + ((vOld.get(i) - vNew.get(i)) * (vOld.get(i) -
vNew.get(i)));
}
return Math.sqrt(sum);

public String vecToString() {


StringBuilder s = new StringBuilder();
s.append("for the vecOld new values are : x1 =");
s.append(this.vOld.get(0));
s.append(" et x2 =");
s.append(this.vOld.get(1));
return s.toString();
}
public void calculateConvergence() throws FileNotFoundException, IOException {
DataOutputStream dos = new DataOutputStream(new FileOutputStream(new
File("out2.csv")));
int iterationNumber = 0;
while (distanceEuclidienne(this.vOld, this.vNew) > 0.0001) {
this.vOld.set(0, this.vNew.get(0));
this.vOld.set(1, this.vNew.get(1));
derivaties();
double ed = distanceEuclidienne(this.vOld, this.vNew);
System.out.println(ed);

dos.writeBytes(Double.toString(ed));
dos.writeBytes(";\n");
System.out.println(vecToString());
iterationNumber++;
}
System.out.println(iterationNumber);
}

public static void main(String[] args) throws FileNotFoundException,


IOException {

ArrayList<Double> vOld = new ArrayList<Double>();


ArrayList<Double> vNew = new ArrayList<Double>();

vOld.add(100.0);
vOld.add(100.0);

vNew.add(10.0);
vNew.add(10.0);
double lambda =0.09641873;
Unconstrained calc = new Unconstrained(vOld, vNew, lambda);
calc.calculateConvergence();
System.out.println("That's it ");

}
Analysis of impact of lambda
Initially lambda was 0.09641873 then we change the value of lambda. With the change of lambda the
no. of iteration change as you can see in graph below.

Lambda No. of Iteration


0.09641873 14
0.01 94
0.001 731
0.0001 5022
0.02 49
0.05 20
0.07 14
0.7 375
0.4 578
0.9 327

No. of Iteration
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0 1000 2000 3000 4000 5000 6000
Conclusion
The unconstrained optimization problem of finding the relative minima x , of f(x) was studied in this
report. The subject of this technical report is the evaluation of different unconstrained optimization
methods; that determine the extremum points of the given objective function(s). By this homework of
unconstraint optimization we learned how easily we can find the solution of complex problems .This
study intended to apply optimization method to vehicle dynamics specifically to generate two optimal
paths; one that would minimize travel time, and another that would maximize tire forces. The
parametric study, demonstrates the effectiveness of the optimization algorithm. Therefore, it can be
concluded that optimal paths can be generated using optimization routine, such as the unconstrained
optimization algorithm of MATLAB. With further development, to improve computation time and
accuracy, this idea can be effectively applied to practical cases such as an automated track testing
procedure.

You might also like