Skip to content

Commit f5cf34e

Browse files
authored
Merge pull request #53 from CST-Group/concepts
Concepts
2 parents 2fa1b72 + d22fbc2 commit f5cf34e

29 files changed

Lines changed: 1069 additions & 367 deletions

.github/workflows/java-ci.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@ jobs:
1515
runs-on: ubuntu-22.04
1616
strategy:
1717
matrix:
18-
java: [ '8', '11']
18+
java: [ '8', '11', '17']
1919
name: JDK ${{ matrix.Java }} build
2020
steps:
21-
- uses: actions/checkout@v3.5.0
21+
- uses: actions/checkout@v4.1.1
2222
- name: Set up Java
23-
uses: actions/setup-java@v3.11.0
23+
uses: actions/setup-java@v4.2.1
2424
with:
2525
java-version: ${{ matrix.java }}
2626
distribution: 'adopt'
2727
cache: gradle
2828
- name: Before Script
2929
run: curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter && chmod +x ./cc-test-reporter && ./cc-test-reporter before-build
3030
- name: Validate Gradle wrapper
31-
uses: gradle/wrapper-validation-action@v1.0.6
31+
uses: gradle/wrapper-validation-action@v3.3.0
3232
- name: Build with Gradle headless
3333
uses: coactions/setup-xvfb@v1.0.1
3434
with:
@@ -40,7 +40,7 @@ jobs:
4040
rm -f ~/.gradle/caches/modules-2/modules-2.lock
4141
rm -f ~/.gradle/caches/modules-2/gc.properties
4242
- name: Test & publish code coverage
43-
uses: paambaati/codeclimate-action@v3.2.0
43+
uses: paambaati/codeclimate-action@v5.0.0
4444
env:
4545
CC_TEST_REPORTER_ID: 430594ee361ff2e93ebf0a942f639b8092c6f17b7c5098f9c75abc404311dfc7
4646
JACOCO_SOURCE_PATH: "${{github.workspace}}/src/main/java"

build.gradle

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,21 @@ plugins {
22
id 'java-library-distribution'
33
id 'jacoco'
44
id 'maven-publish'
5-
id 'com.adarshr.test-logger' version "3.2.0"
5+
id 'com.adarshr.test-logger' version "4.0.0"
66
}
77

88
group = 'com.github.CST-Group'
99

1010
description = "CST"
1111

12-
sourceCompatibility = 1.8
13-
targetCompatibility = 1.8
12+
java {
13+
//sourceCompatibility = JavaVersion.VERSION_11
14+
//targetCompatibility = JavaVersion.VERSION_11
15+
sourceCompatibility = JavaVersion.VERSION_1_8
16+
targetCompatibility = JavaVersion.VERSION_1_8
17+
}
18+
19+
1420
version = '1.4.0'
1521

1622
repositories {
@@ -25,22 +31,26 @@ configurations {
2531
dependencies {
2632
configurations.implementation.extendsFrom(configurations.extraLibs)
2733

28-
api 'com.google.code.gson:gson:2.8.9'
34+
api 'com.google.code.gson:gson:2.10.1'
2935
api 'net.openhft:compiler:2.3.0' // Used by representation/owrl/CodeBuilder.java
3036
api group: 'org.json', name: 'json', version: '20230227'
31-
api group: 'org.opt4j', name: 'opt4j-core', version: '3.1' // Used in GLAS
32-
api group: 'org.opt4j', name: 'opt4j-optimizers', version: '3.1'
33-
api group: 'org.opt4j', name: 'opt4j-viewer', version: '3.1'
34-
api group: 'org.opt4j', name: 'opt4j-benchmarks', version: '3.1'
35-
api group: 'org.opt4j', name: 'opt4j-operators', version: '3.1'
36-
api group: 'org.opt4j', name: 'opt4j-satdecoding', version: '3.1'
37-
api group: 'org.opt4j', name: 'opt4j-tutorial', version: '3.1'
37+
api 'com.google.inject:guice:7.0.0'
38+
//api 'com.github.sdarg:opt4j:3.3.0' // Used in GLAS
39+
//api 'com.github.sdarg:opt4j:4780f4e' // Used in GLAS
40+
api group: 'org.opt4j', name: 'opt4j-core', version: '3.1.4' // Used in GLAS
41+
api group: 'org.opt4j', name: 'opt4j-optimizers', version: '3.1.4'
42+
api group: 'org.opt4j', name: 'opt4j-viewer', version: '3.1.4'
43+
api group: 'org.opt4j', name: 'opt4j-benchmarks', version: '3.1.4'
44+
api group: 'org.opt4j', name: 'opt4j-operators', version: '3.1.4'
45+
api group: 'org.opt4j', name: 'opt4j-satdecoding', version: '3.1.4'
46+
api group: 'org.opt4j', name: 'opt4j-tutorial', version: '3.1.4'
3847
api 'org.antlr:antlr4-runtime:4.5.3' // Used in OwrlBaseListener
3948
api 'com.github.masecla22:java-express:0.2.2'
49+
//api 'io.vacco.murmux:murmux:2.2.2'
4050
implementation 'ch.qos.logback:logback-classic:1.3.6'
41-
//testImplementation group: 'junit', name: 'junit', version: '4.13.2'
42-
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
43-
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
51+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.1'
52+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.1'
53+
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
4454

4555
}
4656

@@ -57,15 +67,15 @@ jar {
5767
}
5868

5969
task javadocJar(type: Jar) {
60-
classifier = 'javadoc'
70+
archiveClassifier = 'javadoc'
6171
from javadoc
6272
from {
6373
configurations.extraLibs.collect { it.isDirectory() ? it : zipTree(it) }
6474
}
6575
javadoc.options.addStringOption('Xdoclint:none', '-quiet') // this is to avoid complaints about documentation missing parameter description
6676
}
6777
task sourcesJar(type: Jar) {
68-
classifier = 'sources'
78+
archiveClassifier = 'sources'
6979
from sourceSets.main.allSource
7080
from {
7181
configurations.extraLibs.collect { it.isDirectory() ? it : zipTree(it) }
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

src/main/java/br/unicamp/cst/attention/CFM.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
* (i) the sum of the values​generated by the bottom-up feature maps and
3535
* (ii) the sum of the values ​​generated by the top-down feature maps.
3636
*
37-
* If (i) > (ii), the winner of the attentional cycle is classified as bottom-up.
38-
* If (ii) > (i), the winner of the attentional cycle is classified as top-down.
37+
* If (i) {@code >} (ii), the winner of the attentional cycle is classified as bottom-up.
38+
* If (ii) {@code >} (i), the winner of the attentional cycle is classified as top-down.
3939
*
4040
* @author leolellisr
4141
*

src/main/java/br/unicamp/cst/behavior/asbac/AffordanceExtractorCodelet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ public List<Percept> searchRelevantPercepts(AffordanceType aff, List<Percept> pe
275275
* Preprocess and init the computation of the cartesian product.
276276
* @param aff
277277
* @param relevantPercepts
278-
* @return a list of map<String,Percept>
278+
* @return a list of {@code Map<String,Percept>}
279279
*/
280280
public List<Map<String, Percept>> getPerceptsCombinations(AffordanceType aff, Map<String, List<Percept>> relevantPercepts){
281281

src/main/java/br/unicamp/cst/core/entities/Codelet.java

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,32 +58,32 @@ public abstract class Codelet implements Runnable, MemoryObserver {
5858
/**
5959
* Activation level of the Codelet. Ranges from 0.0 to 1.0d.
6060
*/
61-
protected double activation = 0.0d;
61+
protected volatile double activation = 0.0d;
6262

6363
/**
6464
* Threshold of the codelet, which is used to decide if it runs or not. If
6565
* activation is equal or greater than activation, codelet runs
6666
* proc().Ranges from 0.0 to 1.0d.
6767
*/
68-
protected double threshold = 0.0d;
68+
protected volatile double threshold = 0.0d;
6969
/**
7070
* Input memories, the ones that are read.
7171
*/
72-
protected List<Memory> inputs = new ArrayList<Memory>();
72+
protected volatile List<Memory> inputs = new ArrayList<Memory>();
7373
/**
7474
* Output memories, the ones that are written.
7575
*/
76-
protected List<Memory> outputs = new ArrayList<Memory>();
76+
protected volatile List<Memory> outputs = new ArrayList<Memory>();
7777
/**
7878
* Input memories, the ones that were broadcasted.
7979
*/
80-
protected List<Memory> broadcast = new ArrayList<Memory>();
80+
protected volatile List<Memory> broadcast = new ArrayList<Memory>();
8181

8282
/** defines if proc() should be automatically called in a loop */
83-
protected boolean loop = true; //
83+
protected volatile boolean loop = true; //
8484

8585
/** defines if codelet is a memory observer (runs when memory input changes) */
86-
protected boolean isMemoryObserver = false; //
86+
protected volatile boolean isMemoryObserver = false; //
8787

8888
/**
8989
* If the proc() method is set to be called automatically in a loop, this
@@ -97,7 +97,7 @@ public abstract class Codelet implements Runnable, MemoryObserver {
9797
* A codelet is a priori enabled to run its proc(). However, if it tries to
9898
* read from a given output and fails, it becomes not able to do so.
9999
*/
100-
private boolean enabled = true;
100+
private volatile boolean enabled = true;
101101

102102
/** Must be zero for this codelet to be enabled */
103103
private int enable_count = 0;
@@ -106,10 +106,10 @@ public abstract class Codelet implements Runnable, MemoryObserver {
106106
protected String name = Thread.currentThread().getName();
107107

108108
/** The time for the last proc() execution for profiling purposes */
109-
long laststarttime = 0l;
109+
volatile long laststarttime = 0l;
110110

111111
/** This variable is a safe lock for multithread access */
112-
public Lock lock = new ReentrantLock();
112+
public volatile Lock lock = new ReentrantLock();
113113

114114
/**
115115
* This method is used in every Codelet to capture input, broadcast and
@@ -131,7 +131,7 @@ public abstract class Codelet implements Runnable, MemoryObserver {
131131
*/
132132
public abstract void proc();
133133

134-
private Timer timer = new Timer();
134+
private volatile Timer timer = new Timer();
135135

136136
/**
137137
* Option for profiling execution times
@@ -172,8 +172,10 @@ public synchronized void run() {
172172
* Starts this codelet execution.
173173
*/
174174
public synchronized void start() {
175+
if (isMemoryObserver == false) {
175176
Thread t = new Thread(this);
176177
t.start();
178+
}
177179
}
178180

179181
/**
@@ -801,17 +803,22 @@ public synchronized void setIsMemoryObserver(boolean isMemoryObserver) {
801803
this.isMemoryObserver = isMemoryObserver;
802804
}
803805

806+
@SuppressWarnings("empty-statement")
804807
public synchronized void setPublishSubscribe(boolean enable) {
805808
if (enable) {
806809
setIsMemoryObserver(true);
807810
for (Memory m : inputs) {
808811
m.addMemoryObserver(this);
809812
}
810813
} else {
811-
setIsMemoryObserver(false);
812814
for (Memory m : inputs) {
813815
m.removeMemoryObserver(this);
814816
}
817+
setIsMemoryObserver(false);
818+
try { this.wait(300L); }
819+
catch(InterruptedException e) {
820+
// just ignore exception
821+
};
815822
run();
816823
}
817824
}

src/main/java/br/unicamp/cst/core/entities/CodeletContainer.java

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,40 @@
77

88
public class CodeletContainer implements Memory {
99

10-
private HashMap<String, List<Memory>> mapInputs = new HashMap<String, List<Memory>>();
10+
private volatile HashMap<String, List<Memory>> mapInputs = new HashMap<String, List<Memory>>();
1111

1212

13-
private HashMap<String, List<Memory>> mapOutputs = new HashMap<String, List<Memory>>();
13+
private volatile HashMap<String, List<Memory>> mapOutputs = new HashMap<String, List<Memory>>();
1414

1515

16-
private HashMap<String, List<Memory>> mapBroadcast = new HashMap<String, List<Memory>>();
16+
private volatile HashMap<String, List<Memory>> mapBroadcast = new HashMap<String, List<Memory>>();
1717

1818
/**
1919
* Output memories, the ones that are written.
2020
*/
21-
protected List<Memory> outputs = new ArrayList<Memory>();
21+
protected volatile List<Memory> outputs = new ArrayList<Memory>();
2222

2323
/**
2424
* Input memories, the ones that were broadcasted.
2525
*/
26-
private List<Memory> broadcast = new ArrayList<Memory>();
26+
private volatile List<Memory> broadcast = new ArrayList<Memory>();
2727

2828
/**
2929
* Input memories, the ones that are read.
3030
*/
31-
protected List<Memory> inputs = new ArrayList<Memory>();
31+
protected volatile List<Memory> inputs = new ArrayList<Memory>();
3232

33-
private ArrayList<Codelet> codelets;
33+
private volatile ArrayList<Codelet> codelets;
3434

3535
/**
36-
* Type of the codelet container
36+
* Name of the codelet container
3737
*/
3838
private String name;
39+
40+
/**
41+
* Id for the CodeletContainer
42+
*/
43+
private Long id;
3944

4045

4146
public CodeletContainer() {
@@ -51,6 +56,27 @@ public CodeletContainer(ArrayList<Codelet> codelets, boolean isToStartCodelets)
5156
this.addCodelet(codelet, isToStartCodelets);
5257
});
5358
}
59+
60+
/**
61+
* Gets the id of the CodeletContainer.
62+
*
63+
* @return the id of the CodeletContainer.
64+
*/
65+
@Override
66+
public synchronized Long getId() {
67+
return this.id;
68+
}
69+
70+
/**
71+
* Sets the id of the CodeletContainer.
72+
*
73+
* @param id
74+
* the id of the CodeletContainer to set.
75+
*/
76+
@Override
77+
public synchronized void setId(Long id) {
78+
this.id = id;
79+
}
5480

5581
/**
5682
* Gets this Codelet activation.

src/main/java/br/unicamp/cst/core/entities/Memory.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,19 @@ public interface Memory {
9898
*/
9999
public void removeMemoryObserver(MemoryObserver memoryObserver);
100100

101+
/**
102+
* Gets the id of the Memory.
103+
*
104+
* @return the id of the Memory.
105+
*/
106+
public Long getId();
107+
108+
/**
109+
* Sets the id of the Memory.
110+
*
111+
* @param id
112+
* the id of the Memory to set.
113+
*/
114+
public void setId(Long id);
101115

102116
}

0 commit comments

Comments
 (0)