Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarvis-K committed Aug 31, 2021
0 parents commit dc0dc31
Show file tree
Hide file tree
Showing 164 changed files with 35,311 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
Binary file added 1569258663717635.mp4
Binary file not shown.
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Learning Sturctured Commnunication

A Tensorflow implementation of `LSC`.


## Code structure

- `./graph_nets`: contains code for establishing communication sturcture.

- `./examples/`: contains scenarios for Ising Model and Battle Game (also models).

- `train_battle.py`: contains code for training Battle Game models

## Requirements Installation
```shell
pip install ./
```
## Compile MAgent platform and run

Before running Battle Game environment, you need to compile it. You can get more helps from: [MAgent](https://github.com/geek-ai/MAgent)

**Steps for compiling**

```shell
cd examples/battle_model
./build.sh
```

**Steps for training models under Battle Game settings**

1. Add python path in your `~/.bashrc` or `~/.zshrc`:

```shell
vim ~/.zshrc
export PYTHONPATH=./examples/battle_model/python:${PYTHONPATH}
source ~/.zshrc
```

2. Run training script for training:

```shell
./runtiny.sh
```
Binary file added data/.DS_Store
Binary file not shown.
Binary file added data/models/.DS_Store
Binary file not shown.
Binary file not shown.
Binary file added data/models/il-1/dqn_6-1995selfnomnw.index
Binary file not shown.
Binary file added data/models/il-1/dqn_6-1995selfnomnw.meta
Binary file not shown.
Binary file not shown.
Binary file added examples/.DS_Store
Binary file not shown.
Binary file added examples/battle_model/.DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions examples/battle_model/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build/
**__pycache__
48 changes: 48 additions & 0 deletions examples/battle_model/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
cmake_minimum_required(VERSION 3.0)

project(magent)

IF (APPLE)
set(CMAKE_CXX_COMPILER "/usr/local/opt/llvm/bin/clang++")
link_directories("/usr/local/opt/llvm/lib")
include_directories( "/usr/local/include" )
link_directories("/usr/local/lib/")
ENDIF()

file(GLOB autopilot_sources src/*.cc src/gridworld/*.cc src/discrete_snake/*.cc src/utility/*.cc)
set(LIB_SRC_FILES ${autopilot_sources})

file(GLOB autopilot_sources src/render/*.cc src/render/*/*.cc src/render/*/*/*.cc)
set(RENDER_SRC_FILES ${autopilot_sources})

set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -std=c++11 -O3")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-variable -Wno-reorder -Wno-sign-compare -Wno-missing-braces")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp -pthread -DDEBUG")

# runtime library
add_library(magent SHARED ${LIB_SRC_FILES})
add_executable(testlib ${LIB_SRC_FILES})

# render
add_executable(render ${RENDER_SRC_FILES})

IF (APPLE)
target_link_libraries(render boost_system jsoncpp argp omp)
ELSE()
target_link_libraries(render boost_system jsoncpp)
ENDIF()

set_target_properties( render
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/render/")

# copy frontend and demo
add_custom_command(
TARGET render POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_SOURCE_DIR}/src/render/frontend/" "${CMAKE_BINARY_DIR}/render"
)

add_custom_command(
TARGET render POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_SOURCE_DIR}/src/render/backend/demo/" "${CMAKE_BINARY_DIR}/render/"
)
13 changes: 13 additions & 0 deletions examples/battle_model/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Battle Game

A cooperative and competitive senario implemented based on MAgent platform

## Code structure

- `./algo`: contains algorithms (MFAC, AC, MFQ, IL)

- `./python` and `./src`: contains engine files

- `./senario_battle.py`: contains code for the logic of play Battle Game

- `./build.sh`: you can run it to compile the MAgent platform
15 changes: 15 additions & 0 deletions examples/battle_model/algo/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from . import q_learning

IL = q_learning.DQN
MSGDQN = q_learning.MsgDQN
GIL=q_learning.GDQN

def spawn_ai(algo_name, sess, env, handle, human_name, max_steps,len_nei=6):
if algo_name == 'il':
model = IL(sess, human_name, handle, env, max_steps, len_nei,memory_size=80)
elif algo_name == 'gil':
model = GIL(sess, human_name, handle, env, max_steps,len_nei, memory_size=8,isHie=False)
elif algo_name == 'msgdqn':
model=MSGDQN(sess,human_name,handle,env,max_steps,len_nei,msg_bits=3,memory_size=80000)

return model
Loading

0 comments on commit dc0dc31

Please sign in to comment.