-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from junqi108/AoMedium_plugin-functionality
Update from upstream
- Loading branch information
Showing
18 changed files
with
229 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[submodule "templates"] | ||
path = templates | ||
url = https://github.com/junqi108/functional-structural-model-templates.git | ||
url = https://github.com/junqi108/functional-structural-model-templates |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import java.io.File; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; | ||
|
||
import models.config.ConfigFile; | ||
|
||
public class FileReader { | ||
// public FileReader() { | ||
|
||
// } | ||
|
||
// public ConfigFile readConfig(String path) { | ||
// File file = new File("src/simulationModels/test.json"); | ||
|
||
// ObjectMapper mapper = new ObjectMapper(); | ||
// ConfigFile config = mapper.readValue(file, ConfigFile.class); | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package functions; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class FunctionCollector { | ||
// XCompiler unable to compile <> with type <IFunction>, so left generic | ||
private List functions; | ||
|
||
public FunctionCollector() { | ||
init(); | ||
} | ||
|
||
public void init() { | ||
functions = new ArrayList(); | ||
} | ||
|
||
public void run() { | ||
for (IFunction function : functions) { | ||
function.run(); | ||
} | ||
} | ||
|
||
public void add(IFunction function) { | ||
functions.add(function); | ||
} | ||
|
||
public List getFunctions() { | ||
return functions; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package functions; | ||
|
||
public class Growth implements IFunction { | ||
public void init() { | ||
println("init Growth"); | ||
} | ||
|
||
public void run() { | ||
println("run Growth"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package functions; | ||
|
||
public interface IFunction { | ||
void init(); | ||
void run(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package functions; | ||
|
||
public class LightInterception implements IFunction { | ||
public void init() { | ||
println("init LightInterception"); | ||
} | ||
|
||
public void run() { | ||
println("run LightInterception"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,43 @@ | ||
/** | ||
* The base module for all organs. | ||
* | ||
* @author James Bristow | ||
* @version 1.0 | ||
* @since 04-08-2022 | ||
*/ | ||
abstract module Organ(float len) extends Sphere(0.1) | ||
{ | ||
{setShader(GREEN);} | ||
} | ||
import java.util.List; | ||
import java.util.ArrayList; | ||
import java.io.File; | ||
|
||
/** | ||
* The bud organ. | ||
* | ||
* @author James Bristow | ||
* @version 1.0 | ||
* @since 04-08-2022 | ||
*/ | ||
module Bud extends Organ(0.1) { | ||
|
||
protected int ID; | ||
|
||
/** | ||
* Gets a plant ID value. | ||
* | ||
* @return The organ ID. | ||
*/ | ||
public int getID() { | ||
return ID; | ||
} | ||
} | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; | ||
|
||
import models.*; | ||
import functions.*; | ||
|
||
static List organs = new ArrayList(); | ||
|
||
protected void init() { | ||
|
||
Leaf leaf = new Leaf(); | ||
File organConfig = new File("/var/model/src/organConfig.yml"); | ||
|
||
/** | ||
* Initialise the model. | ||
* | ||
*/ | ||
protected void init () | ||
[ | ||
Axiom ==> Bud; | ||
] | ||
|
||
/** | ||
* Runs each time step of the simulation. | ||
*/ | ||
public void run () | ||
[ | ||
Bud ==> F(0.5) [RU(30) RH(90) Bud] [RU(-30) RH(90) Bud]; | ||
] | ||
ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); | ||
JsonNode organTree = mapper.readTree(organConfig); | ||
|
||
for (JsonNode organNode : organTree) { | ||
// Create organ instances | ||
String organName = organNode.get("name"); | ||
Class organClass = Class.forName(organName); | ||
GenericOrgan organ = (GenericOrgan) organClass.getDeclaredConstructor().newInstance(); | ||
|
||
JsonNode functions = organNode.get("functions"); | ||
|
||
for (JsonNode functionName : functions) { | ||
String className = functionName.asText(); | ||
Class functionClass = Class.forName(className); | ||
IFunction function = (IFunction) functionClass.getDeclaredConstructor().newInstance(); | ||
|
||
organ.getCollector().add(function); | ||
} | ||
} | ||
} | ||
public void run() { | ||
for (GenericOrgan organ : organs) { | ||
organ.run(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import models.GenericOrgan; | ||
|
||
public class Fruit extends GenericOrgan { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package models; | ||
|
||
import functions.FunctionCollector; | ||
|
||
public abstract class GenericOrgan { | ||
private FunctionCollector collector; | ||
|
||
public FunctionCollector getCollector() { | ||
return collector; | ||
} | ||
|
||
public void run() { | ||
collector.run(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import models.GenericOrgan; | ||
|
||
public class Leaf extends GenericOrgan { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package models.config; | ||
|
||
public class BooleanField extends Field { | ||
|
||
private boolean value; | ||
|
||
public BooleanField(String name, boolean value) { | ||
super(name); | ||
this.value = value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package models.config; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import com.fasterxml.jackson.annotation.*; | ||
|
||
public class ConfigFile { | ||
private Map fields; | ||
|
||
public ConfigFile() { | ||
fields = new HashMap(); | ||
} | ||
|
||
@JsonAnySetter | ||
public void addField(String name, String value) { | ||
fields.put(name, value); | ||
} | ||
|
||
public Map getFields() { | ||
return fields; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package models.config; | ||
|
||
abstract class Field { | ||
private String name; | ||
|
||
public Field(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
leaf: | ||
name: models.Leaf | ||
functions: | ||
- functions.Growth | ||
- functions.LightInterception | ||
|
||
fruit: | ||
name: models.Fruit | ||
functions: | ||
- functions.Growth |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
name: Simple Model | ||
configs: | ||
- environmentConfig.yml | ||
- organConfig.yml |