-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
82 additions
and
0 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,2 +1,3 @@ | ||
# nima | ||
A multi agent framework written in nim | ||
|
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,12 @@ | ||
# Package | ||
|
||
version = "0.1.0" | ||
author = "root-11" | ||
description = "A multi agent framework" | ||
license = "MIT" | ||
srcDir = "src" | ||
|
||
|
||
# Dependencies | ||
|
||
requires "nim >= 2.0.2" |
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,39 @@ | ||
# This is just an example to get you started. A typical library package | ||
# exports the main API in this file. Note that you cannot rename this file | ||
# but you can remove it if you wish. | ||
|
||
type | ||
Sender = int | ||
Receiver = int | ||
Topic = string | ||
Message* = tuple[sender:Sender, receiver:Receiver, topic:Topic] | ||
|
||
|
||
proc copy*(self: Message): Message = | ||
result.sender = self.sender | ||
result.receiver = self.receiver | ||
result.topic = self.topic | ||
|
||
var agent_ids: int = 0 | ||
|
||
type Agent* = object | ||
id*: int | ||
|
||
proc newAgent*(): Agent = | ||
agent_ids += 1 | ||
result.id = agent_ids | ||
|
||
type Scheduler* = object | ||
agents*: seq[Agent] | ||
t*: int = 0 | ||
|
||
proc newScheduler*(): Scheduler = | ||
result.t = 0 | ||
|
||
proc add*(scheduler: var Scheduler, agent: var Agent) = | ||
# Adds agent to the scheduler | ||
scheduler.agents.add(agent) | ||
|
||
proc run*(self: var Scheduler) = | ||
let step: int = 1 | ||
self.t += step |
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 @@ | ||
switch("path", "$projectDir/../src") |
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,29 @@ | ||
# This is just an example to get you started. You may wish to put all of your | ||
# tests into a single file, or separate them into multiple `test1`, `test2` | ||
# etc. files (better names are recommended, just make sure the name starts with | ||
# the letter 't'). | ||
# | ||
# To run these tests, simply execute `nimble test`. | ||
|
||
import unittest | ||
|
||
import nima | ||
|
||
test "can create message": | ||
var msg: Message = (sender:1, receiver:2, topic:"hello") | ||
check msg.sender == 1 | ||
check msg.receiver == 2 | ||
check msg.topic == "hello" | ||
msg_copy = msg.copy() | ||
|
||
|
||
test "can create agent": | ||
var agent = newAgent() | ||
check agent.id == 1 | ||
|
||
test "minimal system": | ||
var agent = newAgent() | ||
var s = newScheduler() | ||
s.add(agent) | ||
s.run() | ||
check s.t == 1 |