Skip to content

Commit

Permalink
initial commits.
Browse files Browse the repository at this point in the history
  • Loading branch information
root-11 committed Feb 9, 2024
1 parent 2a4d609 commit 35cd9b6
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# nima
A multi agent framework written in nim

12 changes: 12 additions & 0 deletions nima.nimble
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"
39 changes: 39 additions & 0 deletions src/nima.nim
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
1 change: 1 addition & 0 deletions tests/config.nims
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
switch("path", "$projectDir/../src")
29 changes: 29 additions & 0 deletions tests/test1.nim
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

0 comments on commit 35cd9b6

Please sign in to comment.