Skip to content

Commit

Permalink
Merge pull request #53 from CST-Group/concepts
Browse files Browse the repository at this point in the history
Concepts
  • Loading branch information
rgudwin authored Apr 24, 2024
2 parents 2fa1b72 + d22fbc2 commit f5cf34e
Show file tree
Hide file tree
Showing 29 changed files with 1,069 additions and 367 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/java-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ jobs:
runs-on: ubuntu-22.04
strategy:
matrix:
java: [ '8', '11']
java: [ '8', '11', '17']
name: JDK ${{ matrix.Java }} build
steps:
- uses: actions/checkout@v3.5.0
- uses: actions/checkout@v4.1.1
- name: Set up Java
uses: actions/setup-java@v3.11.0
uses: actions/setup-java@v4.2.1
with:
java-version: ${{ matrix.java }}
distribution: 'adopt'
cache: gradle
- name: Before Script
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
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@v1.0.6
uses: gradle/wrapper-validation-action@v3.3.0
- name: Build with Gradle headless
uses: coactions/[email protected]
with:
Expand All @@ -40,7 +40,7 @@ jobs:
rm -f ~/.gradle/caches/modules-2/modules-2.lock
rm -f ~/.gradle/caches/modules-2/gc.properties
- name: Test & publish code coverage
uses: paambaati/codeclimate-action@v3.2.0
uses: paambaati/codeclimate-action@v5.0.0
env:
CC_TEST_REPORTER_ID: 430594ee361ff2e93ebf0a942f639b8092c6f17b7c5098f9c75abc404311dfc7
JACOCO_SOURCE_PATH: "${{github.workspace}}/src/main/java"
Expand Down
42 changes: 26 additions & 16 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@ plugins {
id 'java-library-distribution'
id 'jacoco'
id 'maven-publish'
id 'com.adarshr.test-logger' version "3.2.0"
id 'com.adarshr.test-logger' version "4.0.0"
}

group = 'com.github.CST-Group'

description = "CST"

sourceCompatibility = 1.8
targetCompatibility = 1.8
java {
//sourceCompatibility = JavaVersion.VERSION_11
//targetCompatibility = JavaVersion.VERSION_11
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}


version = '1.4.0'

repositories {
Expand All @@ -25,22 +31,26 @@ configurations {
dependencies {
configurations.implementation.extendsFrom(configurations.extraLibs)

api 'com.google.code.gson:gson:2.8.9'
api 'com.google.code.gson:gson:2.10.1'
api 'net.openhft:compiler:2.3.0' // Used by representation/owrl/CodeBuilder.java
api group: 'org.json', name: 'json', version: '20230227'
api group: 'org.opt4j', name: 'opt4j-core', version: '3.1' // Used in GLAS
api group: 'org.opt4j', name: 'opt4j-optimizers', version: '3.1'
api group: 'org.opt4j', name: 'opt4j-viewer', version: '3.1'
api group: 'org.opt4j', name: 'opt4j-benchmarks', version: '3.1'
api group: 'org.opt4j', name: 'opt4j-operators', version: '3.1'
api group: 'org.opt4j', name: 'opt4j-satdecoding', version: '3.1'
api group: 'org.opt4j', name: 'opt4j-tutorial', version: '3.1'
api 'com.google.inject:guice:7.0.0'
//api 'com.github.sdarg:opt4j:3.3.0' // Used in GLAS
//api 'com.github.sdarg:opt4j:4780f4e' // Used in GLAS
api group: 'org.opt4j', name: 'opt4j-core', version: '3.1.4' // Used in GLAS
api group: 'org.opt4j', name: 'opt4j-optimizers', version: '3.1.4'
api group: 'org.opt4j', name: 'opt4j-viewer', version: '3.1.4'
api group: 'org.opt4j', name: 'opt4j-benchmarks', version: '3.1.4'
api group: 'org.opt4j', name: 'opt4j-operators', version: '3.1.4'
api group: 'org.opt4j', name: 'opt4j-satdecoding', version: '3.1.4'
api group: 'org.opt4j', name: 'opt4j-tutorial', version: '3.1.4'
api 'org.antlr:antlr4-runtime:4.5.3' // Used in OwrlBaseListener
api 'com.github.masecla22:java-express:0.2.2'
//api 'io.vacco.murmux:murmux:2.2.2'
implementation 'ch.qos.logback:logback-classic:1.3.6'
//testImplementation group: 'junit', name: 'junit', version: '4.13.2'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.1'
testRuntimeOnly("org.junit.platform:junit-platform-launcher")

}

Expand All @@ -57,15 +67,15 @@ jar {
}

task javadocJar(type: Jar) {
classifier = 'javadoc'
archiveClassifier = 'javadoc'
from javadoc
from {
configurations.extraLibs.collect { it.isDirectory() ? it : zipTree(it) }
}
javadoc.options.addStringOption('Xdoclint:none', '-quiet') // this is to avoid complaints about documentation missing parameter description
}
task sourcesJar(type: Jar) {
classifier = 'sources'
archiveClassifier = 'sources'
from sourceSets.main.allSource
from {
configurations.extraLibs.collect { it.isDirectory() ? it : zipTree(it) }
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
4 changes: 2 additions & 2 deletions src/main/java/br/unicamp/cst/attention/CFM.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
* (i) the sum of the values​generated by the bottom-up feature maps and
* (ii) the sum of the values ​​generated by the top-down feature maps.
*
* If (i) > (ii), the winner of the attentional cycle is classified as bottom-up.
* If (ii) > (i), the winner of the attentional cycle is classified as top-down.
* If (i) {@code >} (ii), the winner of the attentional cycle is classified as bottom-up.
* If (ii) {@code >} (i), the winner of the attentional cycle is classified as top-down.
*
* @author leolellisr
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public List<Percept> searchRelevantPercepts(AffordanceType aff, List<Percept> pe
* Preprocess and init the computation of the cartesian product.
* @param aff
* @param relevantPercepts
* @return a list of map<String,Percept>
* @return a list of {@code Map<String,Percept>}
*/
public List<Map<String, Percept>> getPerceptsCombinations(AffordanceType aff, Map<String, List<Percept>> relevantPercepts){

Expand Down
31 changes: 19 additions & 12 deletions src/main/java/br/unicamp/cst/core/entities/Codelet.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,32 +58,32 @@ public abstract class Codelet implements Runnable, MemoryObserver {
/**
* Activation level of the Codelet. Ranges from 0.0 to 1.0d.
*/
protected double activation = 0.0d;
protected volatile double activation = 0.0d;

/**
* Threshold of the codelet, which is used to decide if it runs or not. If
* activation is equal or greater than activation, codelet runs
* proc().Ranges from 0.0 to 1.0d.
*/
protected double threshold = 0.0d;
protected volatile double threshold = 0.0d;
/**
* Input memories, the ones that are read.
*/
protected List<Memory> inputs = new ArrayList<Memory>();
protected volatile List<Memory> inputs = new ArrayList<Memory>();
/**
* Output memories, the ones that are written.
*/
protected List<Memory> outputs = new ArrayList<Memory>();
protected volatile List<Memory> outputs = new ArrayList<Memory>();
/**
* Input memories, the ones that were broadcasted.
*/
protected List<Memory> broadcast = new ArrayList<Memory>();
protected volatile List<Memory> broadcast = new ArrayList<Memory>();

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

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

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

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

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

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

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

private Timer timer = new Timer();
private volatile Timer timer = new Timer();

/**
* Option for profiling execution times
Expand Down Expand Up @@ -172,8 +172,10 @@ public synchronized void run() {
* Starts this codelet execution.
*/
public synchronized void start() {
if (isMemoryObserver == false) {
Thread t = new Thread(this);
t.start();
}
}

/**
Expand Down Expand Up @@ -801,17 +803,22 @@ public synchronized void setIsMemoryObserver(boolean isMemoryObserver) {
this.isMemoryObserver = isMemoryObserver;
}

@SuppressWarnings("empty-statement")
public synchronized void setPublishSubscribe(boolean enable) {
if (enable) {
setIsMemoryObserver(true);
for (Memory m : inputs) {
m.addMemoryObserver(this);
}
} else {
setIsMemoryObserver(false);
for (Memory m : inputs) {
m.removeMemoryObserver(this);
}
setIsMemoryObserver(false);
try { this.wait(300L); }
catch(InterruptedException e) {
// just ignore exception
};
run();
}
}
Expand Down
42 changes: 34 additions & 8 deletions src/main/java/br/unicamp/cst/core/entities/CodeletContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,40 @@

public class CodeletContainer implements Memory {

private HashMap<String, List<Memory>> mapInputs = new HashMap<String, List<Memory>>();
private volatile HashMap<String, List<Memory>> mapInputs = new HashMap<String, List<Memory>>();


private HashMap<String, List<Memory>> mapOutputs = new HashMap<String, List<Memory>>();
private volatile HashMap<String, List<Memory>> mapOutputs = new HashMap<String, List<Memory>>();


private HashMap<String, List<Memory>> mapBroadcast = new HashMap<String, List<Memory>>();
private volatile HashMap<String, List<Memory>> mapBroadcast = new HashMap<String, List<Memory>>();

/**
* Output memories, the ones that are written.
*/
protected List<Memory> outputs = new ArrayList<Memory>();
protected volatile List<Memory> outputs = new ArrayList<Memory>();

/**
* Input memories, the ones that were broadcasted.
*/
private List<Memory> broadcast = new ArrayList<Memory>();
private volatile List<Memory> broadcast = new ArrayList<Memory>();

/**
* Input memories, the ones that are read.
*/
protected List<Memory> inputs = new ArrayList<Memory>();
protected volatile List<Memory> inputs = new ArrayList<Memory>();

private ArrayList<Codelet> codelets;
private volatile ArrayList<Codelet> codelets;

/**
* Type of the codelet container
* Name of the codelet container
*/
private String name;

/**
* Id for the CodeletContainer
*/
private Long id;


public CodeletContainer() {
Expand All @@ -51,6 +56,27 @@ public CodeletContainer(ArrayList<Codelet> codelets, boolean isToStartCodelets)
this.addCodelet(codelet, isToStartCodelets);
});
}

/**
* Gets the id of the CodeletContainer.
*
* @return the id of the CodeletContainer.
*/
@Override
public synchronized Long getId() {
return this.id;
}

/**
* Sets the id of the CodeletContainer.
*
* @param id
* the id of the CodeletContainer to set.
*/
@Override
public synchronized void setId(Long id) {
this.id = id;
}

/**
* Gets this Codelet activation.
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/br/unicamp/cst/core/entities/Memory.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,19 @@ public interface Memory {
*/
public void removeMemoryObserver(MemoryObserver memoryObserver);

/**
* Gets the id of the Memory.
*
* @return the id of the Memory.
*/
public Long getId();

/**
* Sets the id of the Memory.
*
* @param id
* the id of the Memory to set.
*/
public void setId(Long id);

}
Loading

0 comments on commit f5cf34e

Please sign in to comment.