chore: split repo into code and report parth

This commit is contained in:
Krzysztof Rudnicki 2024-10-27 20:38:11 +01:00
parent ee59f88e4c
commit 69d3df40ea
5 changed files with 363 additions and 17 deletions

307
.gitignore vendored
View File

@ -161,3 +161,310 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
lectures
## Core latex/pdflatex auxiliary files:
*.aux
*.lof
*.log
*.lot
*.fls
*.out
*.toc
*.fmt
*.fot
*.cb
*.cb2
.*.lb
## Intermediate documents:
*.dvi
*.xdv
*-converted-to.*
# these rules might exclude image files for figures etc.
# *.ps
# *.eps
# *.pdf
## Generated if empty string is given at "Please type another file name for output:"
.pdf
## Bibliography auxiliary files (bibtex/biblatex/biber):
*.bbl
*.bcf
*.blg
*-blx.aux
*-blx.bib
*.run.xml
## Build tool auxiliary files:
*.fdb_latexmk
*.synctex
*.synctex(busy)
*.synctex.gz
*.synctex.gz(busy)
*.pdfsync
*.rubbercache
rubber.cache
## Build tool directories for auxiliary files
# latexrun
latex.out/
## Auxiliary and intermediate files from other packages:
# algorithms
*.alg
*.loa
# achemso
acs-*.bib
# amsthm
*.thm
# beamer
*.nav
*.pre
*.snm
*.vrb
# changes
*.soc
# comment
*.cut
# cprotect
*.cpt
# elsarticle (documentclass of Elsevier journals)
*.spl
# endnotes
*.ent
# fixme
*.lox
# feynmf/feynmp
*.mf
*.mp
*.t[1-9]
*.t[1-9][0-9]
*.tfm
#(r)(e)ledmac/(r)(e)ledpar
*.end
*.?end
*.[1-9]
*.[1-9][0-9]
*.[1-9][0-9][0-9]
*.[1-9]R
*.[1-9][0-9]R
*.[1-9][0-9][0-9]R
*.eledsec[1-9]
*.eledsec[1-9]R
*.eledsec[1-9][0-9]
*.eledsec[1-9][0-9]R
*.eledsec[1-9][0-9][0-9]
*.eledsec[1-9][0-9][0-9]R
# glossaries
*.acn
*.acr
*.glg
*.glo
*.gls
*.glsdefs
*.lzo
*.lzs
*.slg
*.slo
*.sls
# uncomment this for glossaries-extra (will ignore makeindex's style files!)
# *.ist
# gnuplot
*.gnuplot
*.table
# gnuplottex
*-gnuplottex-*
# gregoriotex
*.gaux
*.glog
*.gtex
# htlatex
*.4ct
*.4tc
*.idv
*.lg
*.trc
*.xref
# hypdoc
*.hd
# hyperref
*.brf
# knitr
*-concordance.tex
# TODO Uncomment the next line if you use knitr and want to ignore its generated tikz files
# *.tikz
*-tikzDictionary
# listings
*.lol
# luatexja-ruby
*.ltjruby
# makeidx
*.idx
*.ilg
*.ind
# minitoc
*.maf
*.mlf
*.mlt
*.mtc[0-9]*
*.slf[0-9]*
*.slt[0-9]*
*.stc[0-9]*
# minted
_minted*
*.pyg
# morewrites
*.mw
# newpax
*.newpax
# nomencl
*.nlg
*.nlo
*.nls
# pax
*.pax
# pdfpcnotes
*.pdfpc
# sagetex
*.sagetex.sage
*.sagetex.py
*.sagetex.scmd
# scrwfile
*.wrt
# svg
svg-inkscape/
# sympy
*.sout
*.sympy
sympy-plots-for-*.tex/
# pdfcomment
*.upa
*.upb
# pythontex
*.pytxcode
pythontex-files-*/
# tcolorbox
*.listing
# thmtools
*.loe
# TikZ & PGF
*.dpth
*.md5
*.auxlock
# titletoc
*.ptc
# todonotes
*.tdo
# vhistory
*.hst
*.ver
# easy-todo
*.lod
# xcolor
*.xcp
# xmpincl
*.xmpi
# xindy
*.xdy
# xypic precompiled matrices and outlines
*.xyc
*.xyd
# endfloat
*.ttt
*.fff
# Latexian
TSWLatexianTemp*
## Editors:
# WinEdt
*.bak
*.sav
# Texpad
.texpadtmp
# LyX
*.lyx~
# Kile
*.backup
# gummi
.*.swp
# KBibTeX
*~[0-9]*
# TeXnicCenter
*.tps
# auto folder when using emacs and auctex
./auto/*
*.el
# expex forward references with \gathertags
*-tags.tex
# standalone packages
*.sta
# Makeindex log files
*.lpz
# xwatermark package
*.xwm
# REVTeX puts footnotes in the bibliography by default, unless the nofootinbib
# option is specified. Footnotes are the stored in a file with suffix Notes.bib.
# Uncomment the next line to have this generated file ignored.
#*Notes.bib

16
main.py
View File

@ -1,16 +0,0 @@
import metadrive
# Initialize the MetaDrive environment
env = metadrive.MetaDriveEnv()
# Reset the environment to start a new episode
env.reset()
# Run the environment for a few steps
for _ in range(10):
env.step(env.action_space.sample()) # Take random actions
print("Hello, MetaDrive World!") # Print a greeting
# Close the environment after use
env.close()

5
report/report.tex Normal file
View File

@ -0,0 +1,5 @@
\documentclass[12pt]{article}
\begin{document}
Hello world!
$Hello world!$ %math mode
\end{document}

50
script/main.py Normal file
View File

@ -0,0 +1,50 @@
import ray
from ray import tune
from ray.rllib.agents.ppo import PPOTrainer
from metadrive import MultiAgentTIntersectionEnv
import random
# Initialize Ray
ray.init(ignore_reinit_error=True)
# Define a custom environment class that switches between three maps
class MultiMapEnv(MultiAgentTIntersectionEnv):
def __init__(self, config):
# Define available maps
self.maps = ["TIntersection", "Roundabout", "Straight"]
super().__init__(config)
def reset(self):
# Randomly choose a map from the available ones at the start of each episode
self.config["map"] = random.choice(self.maps)
return super().reset()
# Multi-agent configuration with two independent policies
config = {
"env": MultiMapEnv,
"env_config": {
"num_agents": 2, # Set to 2 agents for this multi-agent scenario
},
"framework": "torch", # Use PyTorch as the backend
"num_workers": 1, # Set to 1 worker for simplicity
"multiagent": {
"policies": {
"policy_1": {}, # Configuration for the first agent's policy
"policy_2": {}, # Configuration for the second agent's policy
},
"policy_mapping_fn": lambda agent_id: "policy_1" if agent_id == "agent_1" else "policy_2",
},
}
# Initialize the trainer with PPO algorithm
trainer = PPOTrainer(env=MultiMapEnv, config=config)
# Training loop
print("Starting training for two agents across multiple maps...")
for i in range(10): # Number of training iterations
result = trainer.train()
print(f"Iteration {i + 1}: reward = {result['episode_reward_mean']}")
# Clean up resources
trainer.cleanup()
ray.shutdown()