Large diffs are not rendered by default.

@@ -0,0 +1,92 @@
module pa3;

import java.util.Arrays;

behavior CapitalStarWorker
{
Star stars[];
Double x, y, z;
Double dist;
int workerNum = 0;
int range = 0;
int overflow = 0;

CapitalStarWorker(Star _stars[], int _range, int _workerNum, int _overflow)
{
stars = _stars;
stars[0]<-getAvgDist()@setDist(token);
stars[0]<-getCoord()@setCoord(token);
range = _range;
workerNum = _workerNum;
overflow = _overflow;
}

void setDist(Double _dist)
{
dist = _dist;
}

void setCoord(Double coord[])
{
x = coord[0];
y = coord[1];
z = coord[2];
}

int findBest(Object arr[])
{
int index = -1;
for(int i = 0; i < arr.length; i++)
{
//standardOutput <- println("Checking dist: " + (Double)arr[i]);
if((Double)arr[i] < dist)
{
dist = (Double) arr[i];
index = i;
}
}

return index;
}

void updateIdeal(int index, int beginning)
{
if(index != -1)
{
stars[beginning+index]<-getCoord()@setCoord(token)@
stars[beginning+index]<-getAvgDist()@setDist(token);
}


}

void check()
{
int beginning = range * workerNum;
int ending = beginning+range+overflow;

//standardOutput<-println("beginning: " + beginning + " / ending: " + ending);
join
{
for(int i = beginning; i < ending; i++)
{
stars[i]<-getAvgDist();
}
}@findBest(token)@updateIdeal(token, beginning)@currentContinuation;

}

Double getDist()
{
return dist;
}

Double[] getCoord()
{
Double coord[] = new Double[3];
coord[0] = x;
coord[1] = y;
coord[2] = z;
return coord;
}
}
Binary file not shown.
BIN +5.57 KB pa3/HubStar.class
Binary file not shown.
@@ -0,0 +1,359 @@
package pa3;

// Import declarations generated by the SALSA compiler, do not modify.
import java.io.IOException;
import java.util.Vector;

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.InvocationTargetException;

import salsa.language.Actor;
import salsa.language.ActorReference;
import salsa.language.Message;
import salsa.language.RunTime;
import salsa.language.ServiceFactory;
import gc.WeakReference;
import salsa.language.Token;
import salsa.language.exceptions.*;
import salsa.language.exceptions.CurrentContinuationException;

import salsa.language.UniversalActor;

import salsa.naming.UAN;
import salsa.naming.UAL;
import salsa.naming.MalformedUALException;
import salsa.naming.MalformedUANException;

import salsa.resources.SystemService;

import salsa.resources.ActorService;

// End SALSA compiler generated import delcarations.

import java.util.Arrays;

public class HubStar extends UniversalActor {
public static void main(String args[]) {
UAN uan = null;
UAL ual = null;
if (System.getProperty("uan") != null) {
uan = new UAN( System.getProperty("uan") );
ServiceFactory.getTheater();
RunTime.receivedUniversalActor();
}
if (System.getProperty("ual") != null) {
ual = new UAL( System.getProperty("ual") );

if (uan == null) {
System.err.println("Actor Creation Error:");
System.err.println(" uan: " + uan);
System.err.println(" ual: " + ual);
System.err.println(" Identifier: " + System.getProperty("identifier"));
System.err.println(" Cannot specify an actor to have a ual at runtime without a uan.");
System.err.println(" To give an actor a specific ual at runtime, use the identifier system property.");
System.exit(0);
}
RunTime.receivedUniversalActor();
}
if (System.getProperty("identifier") != null) {
if (ual != null) {
System.err.println("Actor Creation Error:");
System.err.println(" uan: " + uan);
System.err.println(" ual: " + ual);
System.err.println(" Identifier: " + System.getProperty("identifier"));
System.err.println(" Cannot specify an identifier and a ual with system properties when creating an actor.");
System.exit(0);
}
ual = new UAL( ServiceFactory.getTheater().getLocation() + System.getProperty("identifier"));
}
RunTime.receivedMessage();
HubStar instance = (HubStar)new HubStar(uan, ual,null).construct();
gc.WeakReference instanceRef=new gc.WeakReference(uan,ual);
{
Object[] _arguments = { args };

//preAct() for local actor creation
//act() for remote actor creation
if (ual != null && !ual.getLocation().equals(ServiceFactory.getTheater().getLocation())) {instance.send( new Message(instanceRef, instanceRef, "act", _arguments, false) );}
else {instance.send( new Message(instanceRef, instanceRef, "preAct", _arguments, false) );}
}
RunTime.finishedProcessingMessage();
}

public static ActorReference getReferenceByName(UAN uan) { return new HubStar(false, uan); }
public static ActorReference getReferenceByName(String uan) { return HubStar.getReferenceByName(new UAN(uan)); }
public static ActorReference getReferenceByLocation(UAL ual) { return new HubStar(false, ual); }

public static ActorReference getReferenceByLocation(String ual) { return HubStar.getReferenceByLocation(new UAL(ual)); }
public HubStar(boolean o, UAN __uan) { super(false,__uan); }
public HubStar(boolean o, UAL __ual) { super(false,__ual); }
public HubStar(UAN __uan,UniversalActor.State sourceActor) { this(__uan, null, sourceActor); }
public HubStar(UAL __ual,UniversalActor.State sourceActor) { this(null, __ual, sourceActor); }
public HubStar(UniversalActor.State sourceActor) { this(null, null, sourceActor); }
public HubStar() { }
public HubStar(UAN __uan, UAL __ual, Object obj) {
//decide the type of sourceActor
//if obj is null, the actor must be the startup actor.
//if obj is an actorReference, this actor is created by a remote actor

if (obj instanceof UniversalActor.State || obj==null) {
UniversalActor.State sourceActor;
if (obj!=null) { sourceActor=(UniversalActor.State) obj;}
else {sourceActor=null;}

//remote creation message sent to a remote system service.
if (__ual != null && !__ual.getLocation().equals(ServiceFactory.getTheater().getLocation())) {
WeakReference sourceRef;
if (sourceActor!=null && sourceActor.getUAL() != null) {sourceRef = new WeakReference(sourceActor.getUAN(),sourceActor.getUAL());}
else {sourceRef = null;}
if (sourceActor != null) {
if (__uan != null) {sourceActor.getActorMemory().getForwardList().putReference(__uan);}
else if (__ual!=null) {sourceActor.getActorMemory().getForwardList().putReference(__ual);}

//update the source of this actor reference
setSource(sourceActor.getUAN(), sourceActor.getUAL());
activateGC();
}
createRemotely(__uan, __ual, "pa3.HubStar", sourceRef);
}

// local creation
else {
State state = new State(__uan, __ual);

//assume the reference is weak
muteGC();

//the source actor is the startup actor
if (sourceActor == null) {
state.getActorMemory().getInverseList().putInverseReference("rmsp://me");
}

//the souce actor is a normal actor
else if (sourceActor instanceof UniversalActor.State) {

// this reference is part of garbage collection
activateGC();

//update the source of this actor reference
setSource(sourceActor.getUAN(), sourceActor.getUAL());

/* Garbage collection registration:
* register 'this reference' in sourceActor's forward list @
* register 'this reference' in the forward acquaintance's inverse list
*/
String inverseRefString=null;
if (sourceActor.getUAN()!=null) {inverseRefString=sourceActor.getUAN().toString();}
else if (sourceActor.getUAL()!=null) {inverseRefString=sourceActor.getUAL().toString();}
if (__uan != null) {sourceActor.getActorMemory().getForwardList().putReference(__uan);}
else if (__ual != null) {sourceActor.getActorMemory().getForwardList().putReference(__ual);}
else {sourceActor.getActorMemory().getForwardList().putReference(state.getUAL());}

//put the inverse reference information in the actormemory
if (inverseRefString!=null) state.getActorMemory().getInverseList().putInverseReference(inverseRefString);
}
state.updateSelf(this);
ServiceFactory.getNaming().setEntry(state.getUAN(), state.getUAL(), state);
if (getUAN() != null) ServiceFactory.getNaming().update(state.getUAN(), state.getUAL());
}
}

//creation invoked by a remote message
else if (obj instanceof ActorReference) {
ActorReference sourceRef= (ActorReference) obj;
State state = new State(__uan, __ual);
muteGC();
state.getActorMemory().getInverseList().putInverseReference("rmsp://me");
if (sourceRef.getUAN() != null) {state.getActorMemory().getInverseList().putInverseReference(sourceRef.getUAN());}
else if (sourceRef.getUAL() != null) {state.getActorMemory().getInverseList().putInverseReference(sourceRef.getUAL());}
state.updateSelf(this);
ServiceFactory.getNaming().setEntry(state.getUAN(), state.getUAL(),state);
if (getUAN() != null) ServiceFactory.getNaming().update(state.getUAN(), state.getUAL());
}
}

public UniversalActor construct (Star _stars[]) {
Object[] __arguments = { _stars };
this.send( new Message(this, this, "construct", __arguments, null, null) );
return this;
}

public UniversalActor construct() {
Object[] __arguments = { };
this.send( new Message(this, this, "construct", __arguments, null, null) );
return this;
}

public class State extends UniversalActor .State {
public HubStar self;
public void updateSelf(ActorReference actorReference) {
((HubStar)actorReference).setUAL(getUAL());
((HubStar)actorReference).setUAN(getUAN());
self = new HubStar(false,getUAL());
self.setUAN(getUAN());
self.setUAL(getUAL());
self.activateGC();
}

public State() {
this(null, null);
}

public State(UAN __uan, UAL __ual) {
super(__uan, __ual);
addClassName( "pa3.HubStar$State" );
addMethodsForClasses();
}

public void construct() {}

public void process(Message message) {
Method[] matches = getMatches(message.getMethodName());
Object returnValue = null;
Exception exception = null;

if (matches != null) {
if (!message.getMethodName().equals("die")) {activateArgsGC(message);}
for (int i = 0; i < matches.length; i++) {
try {
if (matches[i].getParameterTypes().length != message.getArguments().length) continue;
returnValue = matches[i].invoke(this, message.getArguments());
} catch (Exception e) {
if (e.getCause() instanceof CurrentContinuationException) {
sendGeneratedMessages();
return;
} else if (e instanceof InvocationTargetException) {
sendGeneratedMessages();
exception = (Exception)e.getCause();
break;
} else {
continue;
}
}
sendGeneratedMessages();
currentMessage.resolveContinuations(returnValue);
return;
}
}

System.err.println("Message processing exception:");
if (message.getSource() != null) {
System.err.println("\tSent by: " + message.getSource().toString());
} else System.err.println("\tSent by: unknown");
System.err.println("\tReceived by actor: " + toString());
System.err.println("\tMessage: " + message.toString());
if (exception == null) {
if (matches == null) {
System.err.println("\tNo methods with the same name found.");
return;
}
System.err.println("\tDid not match any of the following: ");
for (int i = 0; i < matches.length; i++) {
System.err.print("\t\tMethod: " + matches[i].getName() + "( ");
Class[] parTypes = matches[i].getParameterTypes();
for (int j = 0; j < parTypes.length; j++) {
System.err.print(parTypes[j].getName() + " ");
}
System.err.println(")");
}
} else {
System.err.println("\tThrew exception: " + exception);
exception.printStackTrace();
}
}

Star stars[];
Double minMaximalDist = -1.0;
Double x = 0.0, y = 0.0, z = 0.0;
void construct(Star _stars[]){
stars = _stars;
}
public void setDist(Double dist) {
minMaximalDist = dist;
}
public void check(Double dist, Star star) {
if (minMaximalDist==-1.0||dist<minMaximalDist) {{
{
Token token_3_0 = new Token();
Token token_3_1 = new Token();
// setDist(dist)
{
Object _arguments[] = { dist };
Message message = new Message( self, self, "setDist", _arguments, null, token_3_0 );
__messages.add( message );
}
// star<-getCoord()
{
Object _arguments[] = { };
Message message = new Message( self, star, "getCoord", _arguments, token_3_0, token_3_1 );
__messages.add( message );
}
// setCoord(token)
{
Object _arguments[] = { token_3_1 };
Message message = new Message( self, self, "setCoord", _arguments, token_3_1, currentMessage.getContinuationToken() );
__messages.add( message );
}
throw new CurrentContinuationException();
}
}
} }
public void setCoord(Double coord[]) {
x = coord[0];
y = coord[1];
z = coord[2];
}
public void compute() {
{
Token token_2_0 = new Token();
// join block
token_2_0.setJoinDirector();
for (int i = 0; i<stars.length; i++){
{
Token token_4_0 = new Token();
// stars[i]<-getMaxDist()
{
Object _arguments[] = { };
Message message = new Message( self, stars[i], "getMaxDist", _arguments, null, token_4_0 );
__messages.add( message );
}
// check(token, stars[i])
{
Object _arguments[] = { token_4_0, stars[i] };
Message message = new Message( self, self, "check", _arguments, token_4_0, token_2_0 );
__messages.add( message );
}
}
}
addJoinToken(token_2_0);
// print()
{
Object _arguments[] = { };
Message message = new Message( self, self, "print", _arguments, token_2_0, null );
__messages.add( message );
}
}
}
public void success() {
}
public void print() {
{
Token token_2_0 = new Token();
// standardOutput<-println("Ideal Hub Star with a minimum maximal distance of "+minMaximalDist)
{
Object _arguments[] = { "Ideal Hub Star with a minimum maximal distance of "+minMaximalDist };
Message message = new Message( self, standardOutput, "println", _arguments, null, token_2_0 );
__messages.add( message );
}
// standardOutput<-println(" located at ("+x+","+y+","+z+")")
{
Object _arguments[] = { " located at ("+x+","+y+","+z+")" };
Message message = new Message( self, standardOutput, "println", _arguments, token_2_0, currentMessage.getContinuationToken() );
__messages.add( message );
}
throw new CurrentContinuationException();
}
}
}
}
@@ -0,0 +1,56 @@
module pa3;

import java.util.Arrays;

behavior HubStar
{
Star stars[];
Double minMaximalDist = -1.0;
Double x = 0.0, y = 0.0, z = 0.0;

HubStar(Star _stars[])
{
stars = _stars;
}

void setDist(Double dist)
{
minMaximalDist = dist;
}

void check(Double dist, Star star)
{
if(minMaximalDist == -1.0 || dist < minMaximalDist)
{
setDist(dist)@
star<-getCoord()@setCoord(token)@currentContinuation;
}
}

void setCoord(Double coord[])
{
x = coord[0];
y = coord[1];
z = coord[2];
}

void compute()
{
join{
for(int i = 0; i < stars.length; i++)
{
stars[i]<-getMaxDist()@check(token, stars[i]);
}
}@print();
}

void success()
{
//nice job
}
void print()
{
standardOutput<-println("Ideal Hub Star with a minimum maximal distance of " + minMaximalDist)@
standardOutput<-println(" located at (" + x + "," + y + "," + z + ")")@currentContinuation;
}
}
BIN +499 Bytes (110%) pa3/Space$State.class
Binary file not shown.
@@ -324,10 +324,24 @@ public void act(String arguments[]) {
}
}
addJoinToken(token_2_0);
// printStars(stars)
// findOptimalStars(stars)
{
Object _arguments[] = { stars };
Message message = new Message( self, self, "printStars", _arguments, token_2_0, null );
Message message = new Message( self, self, "findOptimalStars", _arguments, token_2_0, null );
__messages.add( message );
}
}
}
public void findOptimalStars(Star stars[]) {
HubStar hub = ((HubStar)new HubStar(this).construct(stars));
CapitalStar capital = ((CapitalStar)new CapitalStar(this).construct(stars, 5));
{
// capital<-compute()
{
Object _arguments[] = { };
Message message = new Message( self, capital, "compute", _arguments, null, null );
Object[] _propertyInfo = { new Integer(1000) };
message.setProperty( "wait", _propertyInfo );
__messages.add( message );
}
}
@@ -339,6 +353,8 @@ public void printStars(Star stars[]) {
{
Object _arguments[] = { };
Message message = new Message( self, stars[i], "print", _arguments, null, null );
Object[] _propertyInfo = { new Integer(50) };
message.setProperty( "delay", _propertyInfo );
__messages.add( message );
}
}
@@ -50,17 +50,23 @@ behavior Space
stars[i]<-compare(stars[j]);
}
}
}@printStars(stars);
}@findOptimalStars(stars);
}


void findOptimalStars(Star stars[])
{
HubStar hub = new HubStar(stars);
CapitalStar capital = new CapitalStar(stars, 5);

capital<-compute() : wait (1000);
}

void printStars(Star stars[])
{
for(int i = 0; i < stars.length; i++)
{
stars[i]<-print();
stars[i]<-print() : delay(50);
}
}

}
}
BIN +79 Bytes (100%) pa3/Star$State.class
Binary file not shown.
@@ -294,9 +294,10 @@ public void compare(Star other) {
// updateStats(token, other)
{
Object _arguments[] = { token_2_1, other };
Message message = new Message( self, self, "updateStats", _arguments, token_2_1, null );
Message message = new Message( self, self, "updateStats", _arguments, token_2_1, currentMessage.getContinuationToken() );
__messages.add( message );
}
throw new CurrentContinuationException();
}
}
public void updateStats(Double dist, Star other) {
@@ -325,43 +326,34 @@ public Double[] getCoord() {
coord[2] = z;
return coord;
}
public void setCoord(Double coord[]) {
x = coord[0];
y = coord[1];
z = coord[2];
}
public Double getMinDist() {
return minDist;
}
public void setMinDist(Double dist) {
minDist = dist;
}
public Double getMaxDist() {
return maxDist;
}
public void setMaxDist(Double dist) {
maxDist = dist;
}
public Double getAvgDist() {
return avgDist;
}
public void setAvgDist(Double dist) {
avgDist = dist;
}
public void print() {
{
// standardOutput<-println("(x,y,z) = ("+x+","+y+","+z+")")
{
Object _arguments[] = { "(x,y,z) = ("+x+","+y+","+z+")" };
Message message = new Message( self, standardOutput, "println", _arguments, null, null );
__messages.add( message );
}
}
{
// standardOutput<-println("minDist = "+minDist)
{
Object _arguments[] = { "minDist = "+minDist };
Message message = new Message( self, standardOutput, "println", _arguments, null, null );
__messages.add( message );
}
}
{
// standardOutput<-println("maxDist = "+maxDist)
{
Object _arguments[] = { "maxDist = "+maxDist };
Message message = new Message( self, standardOutput, "println", _arguments, null, null );
__messages.add( message );
}
}
{
// standardOutput<-println("avgDist = "+avgDist)
{
Object _arguments[] = { "avgDist = "+avgDist };
Message message = new Message( self, standardOutput, "println", _arguments, null, null );
__messages.add( message );
}
}
{
// standardOutput<-println("Total stars compared = "+count)
// standardOutput<-println("("+x+","+y+","+z+")")
{
Object _arguments[] = { "Total stars compared = "+count };
Object _arguments[] = { "("+x+","+y+","+z+")" };
Message message = new Message( self, standardOutput, "println", _arguments, null, null );
__messages.add( message );
}
@@ -24,7 +24,7 @@ behavior Star
void compare(Star other)
{
other<-getCoord()
@getDist(token)@updateStats(token, other);
@getDist(token)@updateStats(token, other)@currentContinuation;
}

void updateStats(Double dist, Star other)
@@ -52,12 +52,48 @@ behavior Star
return coord;
}

void setCoord(Double coord[])
{
x = coord[0];
y = coord[1];
z = coord[2];
}

Double getMinDist()
{
return minDist;
}

void setMinDist(Double dist)
{
minDist = dist;
}

Double getMaxDist()
{
return maxDist;
}

void setMaxDist(Double dist)
{
maxDist = dist;
}

Double getAvgDist()
{
return avgDist;
}

void setAvgDist(Double dist)
{
avgDist = dist;
}
void print()
{
standardOutput <- println("(x,y,z) = (" + x + "," + y + "," + z + ")");
standardOutput <-println("minDist = " + minDist);
standardOutput <-println("maxDist = " + maxDist);
standardOutput <-println("avgDist = " + avgDist);
standardOutput <-println("Total stars compared = " + count);
standardOutput <- println("(" + x + "," + y + "," + z + ")");
//standardOutput <- println("minDist = " + minDist);
//standardOutput <- println("maxDist = " + maxDist);
//standardOutput <- println("avgdist = " + avgDist);
//standardOutput <- println("Compared " + count + " stars");
}
}