Skip to content

Commit

Permalink
Correção para solucionar um problema de concorrência
Browse files Browse the repository at this point in the history
  • Loading branch information
rgudwin committed Jun 7, 2016
1 parent 2fc862a commit 90b1a2f
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 40 deletions.
Binary file modified lib/WS3DProxy.jar
Binary file not shown.
Binary file modified lib/cst.jar
Binary file not shown.
Binary file removed lib/ws3d.zip
Binary file not shown.
14 changes: 10 additions & 4 deletions nbproject/build-impl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,12 @@ is divided into following sections:
</not>
</and>
</condition>
<property name="javac.fork" value="${jdkBug6558476}"/>
<condition else="false" property="javac.fork">
<or>
<istrue value="${jdkBug6558476}"/>
<istrue value="${javac.external.vm}"/>
</or>
</condition>
<property name="jar.index" value="false"/>
<property name="jar.index.metainf" value="${jar.index}"/>
<property name="copylibs.rebase" value="true"/>
Expand All @@ -215,6 +220,7 @@ is divided into following sections:
<condition else="" property="testng.debug.mode" value="-mixed">
<istrue value="${junit+testng.available}"/>
</condition>
<property name="java.failonerror" value="true"/>
</target>
<target name="-post-init">
<!-- Empty placeholder for easier customization. -->
Expand Down Expand Up @@ -680,7 +686,7 @@ is divided into following sections:
<sequential>
<property environment="env"/>
<resolve name="profiler.current.path" value="${profiler.info.pathvar}"/>
<java classname="@{classname}" dir="${profiler.info.dir}" fork="true" jvm="${profiler.info.jvm}">
<java classname="@{classname}" dir="${profiler.info.dir}" failonerror="${java.failonerror}" fork="true" jvm="${profiler.info.jvm}">
<jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
<jvmarg value="${profiler.info.jvmargs.agent}"/>
<jvmarg line="${profiler.info.jvmargs}"/>
Expand Down Expand Up @@ -755,7 +761,7 @@ is divided into following sections:
<attribute default="${debug.classpath}" name="classpath"/>
<element name="customize" optional="true"/>
<sequential>
<java classname="@{classname}" dir="${work.dir}" fork="true">
<java classname="@{classname}" dir="${work.dir}" failonerror="${java.failonerror}" fork="true">
<jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
<jvmarg line="${debug-args-line}"/>
<jvmarg value="-Xrunjdwp:transport=${debug-transport},address=${jpda.address}"/>
Expand All @@ -782,7 +788,7 @@ is divided into following sections:
<attribute default="jvm" name="jvm"/>
<element name="customize" optional="true"/>
<sequential>
<java classname="@{classname}" dir="${work.dir}" fork="true">
<java classname="@{classname}" dir="${work.dir}" failonerror="${java.failonerror}" fork="true">
<jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
<jvmarg value="-Dfile.encoding=${runtime.encoding}"/>
<redirector errorencoding="${runtime.encoding}" inputencoding="${runtime.encoding}" outputencoding="${runtime.encoding}"/>
Expand Down
6 changes: 3 additions & 3 deletions nbproject/genfiles.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
build.xml.data.CRC32=c8e907e3
build.xml.script.CRC32=1dae973d
build.xml.stylesheet.CRC32=8064a381@1.75.2.48
build.xml.stylesheet.CRC32=8064a381@1.79.1.48
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=c8e907e3
nbproject/build-impl.xml.script.CRC32=8b8d33fc
nbproject/build-impl.xml.stylesheet.CRC32=876e7a8f@1.75.2.48
nbproject/build-impl.xml.script.CRC32=ec67af1d
nbproject/build-impl.xml.stylesheet.CRC32=05530350@1.79.1.48
5 changes: 3 additions & 2 deletions nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ javac.classpath=\
${file.reference.json.jar}:\
${file.reference.junit-4.9b4.jar}:\
${file.reference.log4j-1.2.16.jar}:\
${file.reference.cst.jar}:\
${file.reference.WS3DProxy.jar}
${file.reference.WS3DProxy.jar}:\
${file.reference.cst.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
javac.external.vm=false
javac.processorpath=\
${javac.classpath}
javac.source=1.7
Expand Down
2 changes: 1 addition & 1 deletion src/AgentMind.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
*/
public class AgentMind extends Mind {

private static int creatureBasicSpeed=1;
private static int creatureBasicSpeed=3;
private static int reachDistance=50;

public AgentMind(Environment env) {
Expand Down
3 changes: 2 additions & 1 deletion src/ExperimentMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* Klaus Raizer, Andre Paraense, Ricardo Ribeiro Gudwin
*****************************************************************************/

import java.util.logging.Level;
import java.util.logging.Logger;

/**
Expand All @@ -32,7 +33,7 @@ public class ExperimentMain {

public ExperimentMain() {
//WS3DProxy.logger.setLevel(Level.SEVERE);

Logger.getLogger("codelets").setLevel(Level.SEVERE);
// Create Environment
Environment env=new Environment(); //Creates only a creature and some apples
AgentMind a = new AgentMind(env); // Creates the Agent Mind and start it
Expand Down
8 changes: 5 additions & 3 deletions src/codelets/motor/HandsActionCodelet.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import br.unicamp.cst.core.entities.Codelet;
import br.unicamp.cst.core.entities.MemoryObject;
import java.util.Random;
import java.util.logging.Logger;
import ws3dproxy.model.Creature;

/**
Expand All @@ -42,6 +43,7 @@ public class HandsActionCodelet extends Codelet{
private String previousHandsAction="";
private Creature c;
private Random r = new Random();
static Logger log = Logger.getLogger(HandsActionCodelet.class.getCanonicalName());

public HandsActionCodelet(Creature nc) {
c = nc;
Expand All @@ -68,7 +70,7 @@ public void proc() {
} catch (Exception e) {

}
System.out.println("Sending Put In Sack command to agent:****** "+objectName+"**********");
log.info("Sending Put In Sack command to agent:****** "+objectName+"**********");


// }
Expand All @@ -79,15 +81,15 @@ public void proc() {
} catch (Exception e) {

}
System.out.println("Sending Eat command to agent:****** "+objectName+"**********");
log.info("Sending Eat command to agent:****** "+objectName+"**********");
}
if(action.equals("BURY")){
try {
c.hideIt(objectName);
} catch (Exception e) {

}
System.out.println("Sending Bury command to agent:****** "+objectName+"**********");
log.info("Sending Bury command to agent:****** "+objectName+"**********");
}
}
// else if (jsonAction.has("ACTION")) {
Expand Down
40 changes: 14 additions & 26 deletions src/codelets/motor/LegsActionCodelet.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import br.unicamp.cst.core.entities.Codelet;
import br.unicamp.cst.core.entities.MemoryObject;
import java.util.Random;
import java.util.logging.Logger;
import org.json.JSONException;
import ws3dproxy.model.Creature;

Expand All @@ -44,6 +45,7 @@ public class LegsActionCodelet extends Codelet{
private Creature c;
double old_angle = 0;
int k=0;
static Logger log = Logger.getLogger(LegsActionCodelet.class.getCanonicalName());

public LegsActionCodelet(Creature nc) {
c = nc;
Expand All @@ -57,70 +59,56 @@ public void accessMemoryObjects() {
@Override
public void proc() {

//System.out.println(legsActionMO.toString()+" old: "+previousLegsAction+previousLegsAction.hashCode());
String comm = (String) legsActionMO.getI();
//System.out.println("Legs: "+comm+" old: "+previousLegsAction+" k: "+k);
if (comm == null) comm = "";
Random r = new Random();

if(!comm.equals("") ){

try {

JSONObject command=new JSONObject(comm);
if (command.has("ACTION")) {
int x=0,y=0;
String action=command.getString("ACTION");
if(action.equals("FORAGE")){
//if (!comm.equals(previousLegsAction)) {
try {
x = r.nextInt(600);
y = r.nextInt(800);
if (!comm.equals(previousLegsAction))
System.out.println("Sending Forage command to agent:****** ("+x+","+y+") **********");
c.rotate(5);

//c.moveto(1,x,y);

if (!comm.equals(previousLegsAction))
log.info("Sending Forage command to agent");
try {
c.rotate(0.01);
} catch (Exception e) {
e.printStackTrace();
}
//}
//else {System.out.println("comm: "+comm+" previous: "+previousLegsAction);}
}
else if(action.equals("GOTO")){
if (!comm.equals(previousLegsAction)) {
double speed=command.getDouble("SPEED");
double targetx=command.getDouble("X");
double targety=command.getDouble("Y");
if (!comm.equals(previousLegsAction)) System.out.println("Sending move command to agent: ["+targetx+","+targety+"]");
if (!comm.equals(previousLegsAction))
log.info("Sending move command to agent: ["+targetx+","+targety+"]");
try {
c.moveto(speed, targetx, targety);
} catch(Exception e) {
e.printStackTrace();
e.printStackTrace();
}
previousTargetx=targetx;
previousTargety=targety;
}
//else {System.out.println("comm: "+comm+" previous: "+previousLegsAction);}
}else{
System.out.println("Sending stop command to agent");

} else {
log.info("Sending stop command to agent");
try {
c.moveto(0,0,0);
} catch(Exception e) {
e.printStackTrace();
}
}
}
}
//System.out.println("oldvalue:"+previousLegsAction.hashCode()+" new:"+legsActionMO.getInfo().hashCode());
previousLegsAction=comm;
//System.out.println("oldvalue2:"+previousLegsAction.hashCode()+" new2:"+legsActionMO.getInfo().hashCode());
k++;

k++;
} catch (JSONException e) {e.printStackTrace();}

}

}//end proc

@Override
Expand Down

0 comments on commit 90b1a2f

Please sign in to comment.