forked from srieger/verteilte-systeme-bsc-ai-examples
Sebastian Rieger
7 years ago
2 changed files with 130 additions and 130 deletions
-
2VerteilteSysteme-Examples/src/verteiltesysteme/mandelbrot/rmi/MGuiRMI.java
-
258VerteilteSysteme-Examples/src/verteiltesysteme/mandelbrot/rmi/RMIMandelbrotCalculationsServer.java
@ -1,130 +1,130 @@ |
|||||
package verteiltesysteme.mandelbrot.rmi; |
|
||||
|
|
||||
import java.rmi.registry.LocateRegistry; |
|
||||
import java.rmi.registry.Registry; |
|
||||
import java.rmi.server.UnicastRemoteObject; |
|
||||
|
|
||||
class Complex { |
|
||||
double r; |
|
||||
double i; |
|
||||
|
|
||||
Complex() { |
|
||||
r = 0.0; |
|
||||
i = 0.0; |
|
||||
} |
|
||||
|
|
||||
Complex(double r, double i) { |
|
||||
this.r = r; |
|
||||
this.i = i; |
|
||||
} |
|
||||
|
|
||||
void mulBy(Complex other) { |
|
||||
double rTmp = this.r * other.r - this.i * other.i; |
|
||||
this.i = this.r * other.i + this.i * other.r; |
|
||||
this.r = rTmp; |
|
||||
} |
|
||||
|
|
||||
void add(Complex other) { |
|
||||
this.r += other.r; |
|
||||
this.i += other.i; |
|
||||
} |
|
||||
|
|
||||
void sub(Complex other) { |
|
||||
this.r -= other.r; |
|
||||
this.i -= other.i; |
|
||||
} |
|
||||
|
|
||||
double absValue() { |
|
||||
return Math.sqrt(this.r * this.r + this.i * this.i); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
public class RMIMandelbrotCalculationsServer implements RMIMandelbrotCalculationsInterface { |
|
||||
public RMIMandelbrotCalculationsServer() {} |
|
||||
|
|
||||
public static void main(String args[]) { |
|
||||
|
|
||||
try { |
|
||||
RMIMandelbrotCalculationsServer obj = new RMIMandelbrotCalculationsServer(); |
|
||||
RMIMandelbrotCalculationsInterface stub = (RMIMandelbrotCalculationsInterface) UnicastRemoteObject.exportObject(obj, 0); |
|
||||
|
|
||||
// Bind the remote object's stub in the registry |
|
||||
Registry registry = LocateRegistry.getRegistry(); |
|
||||
registry.bind("RMIEchoInterface", stub); |
|
||||
|
|
||||
System.err.println("Server ready"); |
|
||||
} catch (Exception e) { |
|
||||
System.err.println("Server exception: " + e.toString()); |
|
||||
e.printStackTrace(); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
// hier wird das Ergebnis von iterateAll() gespeichert |
|
||||
protected int[] result = null; |
|
||||
|
|
||||
// der augenblicklich gewaehlte Ausschnitt |
|
||||
//double ULx = -2, ULy = -2, LRx = 2, LRy = 2; |
|
||||
double ULx = -0.16099999999999995, ULy = -0.9365333333333333, LRx = -0.03533333333333327, LRy = -0.8108666666666666; |
|
||||
|
|
||||
int iterateOnePoint(Complex c, int maxIterations, double maxModulus) { |
|
||||
Complex z = new Complex(0., 0.); |
|
||||
|
|
||||
for (int i = 0; i < maxIterations; i++) { |
|
||||
z.mulBy(z); |
|
||||
z.add(c); |
|
||||
double m = z.absValue(); |
|
||||
if (m > maxModulus) { |
|
||||
return i; |
|
||||
} |
|
||||
} |
|
||||
return maxIterations; |
|
||||
} |
|
||||
|
|
||||
public void iterateAllPoints(int maxIterations, double nrPointsX, double nrPointsY) { |
|
||||
|
|
||||
this.result = new int[(int) (nrPointsX * nrPointsY)]; |
|
||||
|
|
||||
int counter = 0; |
|
||||
double stepX = (this.LRx - this.ULx) / nrPointsX; |
|
||||
double stepY = (this.LRy - this.ULy) / nrPointsY; |
|
||||
double i = this.ULy; |
|
||||
for (int cy = 0; cy < nrPointsY; cy++) { |
|
||||
double r = this.ULx; |
|
||||
for (int cx = 0; cx < nrPointsX; cx++) { |
|
||||
Complex c = new Complex(r, i); |
|
||||
this.result[counter] = maxIterations - this.iterateOnePoint(c, maxIterations, 2.0); |
|
||||
counter += 1; |
|
||||
r += stepX; |
|
||||
} |
|
||||
i += stepY; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
public int[] getResult() { |
|
||||
return this.result; |
|
||||
} |
|
||||
|
|
||||
public double getULx() { |
|
||||
return this.ULx; |
|
||||
} |
|
||||
|
|
||||
public double getLRx() { |
|
||||
return this.LRx; |
|
||||
} |
|
||||
|
|
||||
public double getULy() { |
|
||||
return this.ULy; |
|
||||
} |
|
||||
|
|
||||
public double getLRy() { |
|
||||
return this.LRy; |
|
||||
} |
|
||||
|
|
||||
public void setView(double ULx, double ULy, double LRx, double LRy) { |
|
||||
this.ULx = ULx; |
|
||||
this.ULy = ULy; |
|
||||
this.LRx = LRx; |
|
||||
this.LRy = LRy; |
|
||||
} |
|
||||
|
|
||||
|
package verteiltesysteme.mandelbrot.rmi; |
||||
|
|
||||
|
import java.rmi.registry.LocateRegistry; |
||||
|
import java.rmi.registry.Registry; |
||||
|
import java.rmi.server.UnicastRemoteObject; |
||||
|
|
||||
|
class Complex { |
||||
|
double r; |
||||
|
double i; |
||||
|
|
||||
|
Complex() { |
||||
|
r = 0.0; |
||||
|
i = 0.0; |
||||
|
} |
||||
|
|
||||
|
Complex(double r, double i) { |
||||
|
this.r = r; |
||||
|
this.i = i; |
||||
|
} |
||||
|
|
||||
|
void mulBy(Complex other) { |
||||
|
double rTmp = this.r * other.r - this.i * other.i; |
||||
|
this.i = this.r * other.i + this.i * other.r; |
||||
|
this.r = rTmp; |
||||
|
} |
||||
|
|
||||
|
void add(Complex other) { |
||||
|
this.r += other.r; |
||||
|
this.i += other.i; |
||||
|
} |
||||
|
|
||||
|
void sub(Complex other) { |
||||
|
this.r -= other.r; |
||||
|
this.i -= other.i; |
||||
|
} |
||||
|
|
||||
|
double absValue() { |
||||
|
return Math.sqrt(this.r * this.r + this.i * this.i); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public class RMIMandelbrotCalculationsServer implements RMIMandelbrotCalculationsInterface { |
||||
|
public RMIMandelbrotCalculationsServer() {} |
||||
|
|
||||
|
public static void main(String args[]) { |
||||
|
|
||||
|
try { |
||||
|
RMIMandelbrotCalculationsServer obj = new RMIMandelbrotCalculationsServer(); |
||||
|
RMIMandelbrotCalculationsInterface stub = (RMIMandelbrotCalculationsInterface) UnicastRemoteObject.exportObject(obj, 0); |
||||
|
|
||||
|
// Bind the remote object's stub in the registry |
||||
|
Registry registry = LocateRegistry.getRegistry(); |
||||
|
registry.bind("RMIMandelbrotCalculationsInterface", stub); |
||||
|
|
||||
|
System.err.println("Server ready"); |
||||
|
} catch (Exception e) { |
||||
|
System.err.println("Server exception: " + e.toString()); |
||||
|
e.printStackTrace(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// hier wird das Ergebnis von iterateAll() gespeichert |
||||
|
protected int[] result = null; |
||||
|
|
||||
|
// der augenblicklich gewaehlte Ausschnitt |
||||
|
//double ULx = -2, ULy = -2, LRx = 2, LRy = 2; |
||||
|
double ULx = -0.16099999999999995, ULy = -0.9365333333333333, LRx = -0.03533333333333327, LRy = -0.8108666666666666; |
||||
|
|
||||
|
int iterateOnePoint(Complex c, int maxIterations, double maxModulus) { |
||||
|
Complex z = new Complex(0., 0.); |
||||
|
|
||||
|
for (int i = 0; i < maxIterations; i++) { |
||||
|
z.mulBy(z); |
||||
|
z.add(c); |
||||
|
double m = z.absValue(); |
||||
|
if (m > maxModulus) { |
||||
|
return i; |
||||
|
} |
||||
|
} |
||||
|
return maxIterations; |
||||
|
} |
||||
|
|
||||
|
public void iterateAllPoints(int maxIterations, double nrPointsX, double nrPointsY) { |
||||
|
|
||||
|
this.result = new int[(int) (nrPointsX * nrPointsY)]; |
||||
|
|
||||
|
int counter = 0; |
||||
|
double stepX = (this.LRx - this.ULx) / nrPointsX; |
||||
|
double stepY = (this.LRy - this.ULy) / nrPointsY; |
||||
|
double i = this.ULy; |
||||
|
for (int cy = 0; cy < nrPointsY; cy++) { |
||||
|
double r = this.ULx; |
||||
|
for (int cx = 0; cx < nrPointsX; cx++) { |
||||
|
Complex c = new Complex(r, i); |
||||
|
this.result[counter] = maxIterations - this.iterateOnePoint(c, maxIterations, 2.0); |
||||
|
counter += 1; |
||||
|
r += stepX; |
||||
|
} |
||||
|
i += stepY; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public int[] getResult() { |
||||
|
return this.result; |
||||
|
} |
||||
|
|
||||
|
public double getULx() { |
||||
|
return this.ULx; |
||||
|
} |
||||
|
|
||||
|
public double getLRx() { |
||||
|
return this.LRx; |
||||
|
} |
||||
|
|
||||
|
public double getULy() { |
||||
|
return this.ULy; |
||||
|
} |
||||
|
|
||||
|
public double getLRy() { |
||||
|
return this.LRy; |
||||
|
} |
||||
|
|
||||
|
public void setView(double ULx, double ULy, double LRx, double LRy) { |
||||
|
this.ULx = ULx; |
||||
|
this.ULy = ULy; |
||||
|
this.LRx = LRx; |
||||
|
this.LRy = LRy; |
||||
|
} |
||||
|
|
||||
} |
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue