Skip to content

Commit

Permalink
Started working again, on Samaritan, adding fluent interface, reviewi…
Browse files Browse the repository at this point in the history
…ng code
  • Loading branch information
harold authored and DaceKonn committed Dec 7, 2014
1 parent 016ac01 commit 3933c1d
Show file tree
Hide file tree
Showing 14 changed files with 163 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .idea/libraries/commons_math3_3_2.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/libraries/controlP5.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/libraries/core.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions BiomorphGenerate/BiomorphGenerate.iml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="1.7" jdkType="JavaSDK" />
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="commons-math3-3.2" level="project" />
<orderEntry type="module" module-name="Iterations" exported="" />
</component>
</module>

</module>
58 changes: 50 additions & 8 deletions BiomorphGenerate/src/BiomorphGenerate/BiomorphGenerate.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,54 @@ public BiomorphGenerate()
{
}

//<editor-fold desc="With Section">
public BiomorphGenerate WithPointA(MyPoint pointA)
{
point_a = pointA;
return this;
}

public BiomorphGenerate WithPointB(MyPoint pointB)
{
point_b = pointB;
return this;
}

public BiomorphGenerate WithSize(int size)
{
this.size = size;
return this;
}

public BiomorphGenerate WithIterations(int iterations)
{
this.iterations = iterations;
return this;
}

public BiomorphGenerate WithThershold(double threshold)
{
this.threshold = threshold;
return this;
}

public BiomorphGenerate WithMethod(Iterate method)
{
this.method = method;
return this;
}

//</editor-fold>

public void Default()
{
point_a = new MyPoint(-2.0, 2.0);
point_b = new MyPoint(2.0, -2.0);
size = 2000;
size = 700;
iterations = 30;
threshold = 10.0;
threshold = 100.0;
method = new Iterate();
method.setEquationPolynomial(null,2.0,-1.5,8.5,9.5);
method.setEquationPolynomial(new Complex(0,0),1.0,0.0,1.0,0.0);
method.setIterationPicard(0.5);
}

Expand All @@ -46,12 +85,15 @@ private boolean MagnitudeCheck(Complex x, int method)
case 1:
if (FastMath.abs(x.getReal())+FastMath.abs(x.getImaginary())>threshold)
return true;
break;
case 2:
if (x.abs() > threshold)
return true;
break;
case 3:
if (FastMath.sqrt(FastMath.pow(x.getReal(),2)+FastMath.pow(x.getImaginary(),2))>threshold)
return true;
break;
}
return false;
}
Expand Down Expand Up @@ -98,7 +140,7 @@ private boolean MagnitudeCheck(Complex x, int method)
if (x.abs() > threshold)
return true;
case 3:
if (FastMath.sqrt(FastMath.pow(x.getReal(),2)+FastMath.pow(x.getImaginary(),2))>threshold)
if (FastMath.sqrt(FastMath.pow(x.getReal(), 2) + FastMath.pow(x.getImaginary(), 2))>threshold)
return true;
}
return false;
Expand Down Expand Up @@ -142,19 +184,19 @@ private void generate_single()
for (int j = 0; j<size; j++)
{
method.setInput(new Complex(i*step+point_a.GetX(),j*step-point_a.GetY()));

Complex rslt = new Complex(0.0,0.0);
tmp[i][j] = -1;
for (int l = 0; l<iterations;l++)
{
method.Calculate(true);
if (MagnitudeCheck(method.getInput(),magCheck))
rslt = method.Calculate(true);
if (MagnitudeCheck(rslt,magCheck))
{
tmp[i][j] = l;
break;
}
}
if (tmp[i][j] != -1)
if ((FastMath.abs(method.getInput().getReal())<threshold||FastMath.abs(method.getInput().getImaginary())<threshold))
if ((FastMath.abs(rslt.getReal())<threshold||FastMath.abs(rslt.getImaginary())<threshold))
tmp[i][j] = -1;
}
}
Expand Down
5 changes: 2 additions & 3 deletions ConsoleOverlay/ConsoleOverlay.iml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="1.7" jdkType="JavaSDK" />
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="BiomorphGenerate" exported="" />
<orderEntry type="library" exported="" name="commons-math3-3.2" level="project" />
</component>
</module>

</module>
10 changes: 5 additions & 5 deletions ConsoleOverlay/src/ConsoleOverlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ public static void main(String args[])
System.out.println(bm.GetGridString());
// System.out.println(bm.toString());

/* long time = System.nanoTime();
long time = System.nanoTime();
BiomorphGenerate bg = new BiomorphGenerate();
bg.Default();
bm = bg.GetBiomorph(true);
/* bm = bg.GetBiomorph(true);
System.out.println("Generated multicore: "+((System.nanoTime() - time)/1000000));
bm.GetGridString();
System.out.println();
time = (System.nanoTime() - time)/1000000;
System.out.println("Miliseconds elapsed: "+time);
System.out.println("Miliseconds elapsed: "+time);*/

System.out.println();

Expand All @@ -55,9 +55,9 @@ public static void main(String args[])
bg.Default();
bm = bg.GetBiomorph(false);
System.out.println("Generated singlecore: "+((System.nanoTime() - time)/1000000));
bm.GetGridString();
// System.out.println( bm.GetGridString());
System.out.println();
time = (System.nanoTime() - time)/1000000;
System.out.println("Miliseconds elapsed: "+time);*/
System.out.println("Miliseconds elapsed: "+time);
}
}
5 changes: 2 additions & 3 deletions Equations/Equations.iml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="commons-math3-3.2" level="project" />
</component>
</module>

</module>
17 changes: 12 additions & 5 deletions Equations/src/Equations/EquationBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public EquationBuilder(EquationBuilder equation)
public void ChangeInput(Complex input)
{
CloseAll();
this.input = input;
left.get(0).SetBaseInput(input);
}

Expand All @@ -59,7 +60,13 @@ public String GetJoins()
public Complex GetValue()
{
CloseAll();
return left.get(0).GetValue();
Complex tmp; //= left.get(0).GetValue();
tmp = input.pow(3.0);//input.pow(2.0).multiply(1.0).add(input.pow(0.0).multiply(0.0));
if (tmp.isNaN())
{
tmp = new Complex(0.0,0.0);
}
return tmp;
}

public String GetEquationString()
Expand Down Expand Up @@ -167,11 +174,11 @@ public void Devide(Complex param, boolean base)
public void PredefinedPolinomialSimple(double a, double b, double m, double n)
{
Power(new Complex(m, 0.0));
Multiply(new Complex(a, 0.0), false);
//Multiply(new Complex(a, 0.0), false);
Close();
Add(input, true);
Power(new Complex(n, 0.0));
Multiply(new Complex(b, 0.0), false);
//Add(input, true);
//Power(new Complex(n, 0.0));
//Multiply(new Complex(b, 0.0), false);
CloseAll();
}
}
5 changes: 2 additions & 3 deletions Iterations/Iterations.iml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="Equations" exported="" />
<orderEntry type="library" exported="" name="commons-math3-3.2" level="project" />
</component>
</module>

</module>
7 changes: 6 additions & 1 deletion Iterations/src/Iterations/Iterate.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package Iterations;

import Equations.Equation;
import Equations.EquationBuilder;
import org.apache.commons.math3.complex.Complex;
/**
* Created by harold on 29.04.14.
*/
public class Iterate {
private Equation equation;
private EquationBuilder eqBuilder;
private Iteration iteration;
private boolean equation_set = false;
private boolean iteration_set = false;
Expand Down Expand Up @@ -59,6 +61,8 @@ public void setInput(Complex input)
public void setEquationPolynomial(Complex input, double ex, double fx, double xpa, double xpb)
{
equation = new Equations.Polynomial(input, ex, fx, xpa, xpb);
eqBuilder = new EquationBuilder(input);
eqBuilder.PredefinedPolinomialSimple(ex, fx, xpa, xpb);
equation_set = true;
}

Expand All @@ -72,7 +76,8 @@ public void setIterationPicard(double u)
{
if (equation_set)
{
iteration = new Picard(equation,u);
// iteration = new Picard(equation,u);
iteration = new Picard(eqBuilder,u);
iteration_set = true;
}
// else parent.println("Error: In Iterations.Iterate - can't set iteration because the equation is not set");
Expand Down
13 changes: 11 additions & 2 deletions Iterations/src/Iterations/Iteration.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package Iterations;

import Equations.Equation;
import Equations.EquationBuilder;
import org.apache.commons.math3.complex.Complex;

/**
Expand All @@ -10,21 +11,29 @@ abstract public class Iteration
{
//private Complex input;
protected Equation equation;
protected EquationBuilder eqBuilder;

public Iteration(Equation equation)
{
//this.input = input;
this.equation = equation;
}
public Iteration(EquationBuilder equationBuilder)
{
//this.input = input;
this.eqBuilder = new EquationBuilder(equationBuilder);
}

public Complex getInput()
{
return equation.getInput();
//return equation.getInput();
return eqBuilder.input;
}

public void setInput(Complex input)
{
equation.setInput(input);
// equation.setInput(input);
eqBuilder.ChangeInput(input);
}

abstract public Complex Calculate(boolean withUpdate);
Expand Down
13 changes: 11 additions & 2 deletions Iterations/src/Iterations/Picard.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import Equations.Equation;

import Equations.EquationBuilder;
import org.apache.commons.math3.complex.Complex;

/**
Expand All @@ -16,14 +17,22 @@ public Picard(Equation equation, double u)
super(equation);
this.u = u;
}
public Picard(EquationBuilder equationBuilder, double u)
{
super(equationBuilder);
this.u = u;
}

@Override
public Complex Calculate(boolean withUpdate)
{
Complex tmp = equation.Calculate().add(u);

//Complex tmp = equation.Calculate().add(u);
Complex tmp = eqBuilder.GetValue().add(u);
if (withUpdate)
{
equation.setInput(tmp);
//equation.setInput(tmp);
eqBuilder.ChangeInput(tmp);
}
return tmp;
}
Expand Down
Loading

0 comments on commit 3933c1d

Please sign in to comment.