Skip to content

EC2021のシミュレーションプログラムとその実行サンプルコードです.

Notifications You must be signed in to change notification settings

yskgt-sim/ec_2021

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ec_2021

概要

EC2021のシミュレーション・プログラムとサンプルコードを配布しています.

  • Darwin/: MacOS用のシミュレーション・プログラムです.
  • Linux/: Linux用のシミュレーション・プログラムです.
  • Windows/: Windows用のシミュレーション・プログラムです.
  • example_sop.py: 単目的部門の最適化用サンプルコード(python)です.
  • example_mop.py: 多目的部門の最適化用サンプルコード(python)です.
  • requirements.txt: サンプルコードの実行に必要な依存パッケージ一覧です.

インストール

申込後にダウンロード可能となる仮想合成人口データとシナリオファイルを配置します.

$ ls
Darwin
Linux
README.md
Windows
data
example_mop.py
example_sop.py
requirements.txt

dataディレクトリには次のファイルが配置されていることを確認してください.

$ ls data
 hakodate_01.pkl
 hakodate_02.pkl
 hakodate_03.pkl
 naha_01.pkl
 naha_02.pkl
 naha_03.pkl
 scenario.csv

Python 3.7以上3.9以下がインストールされているものとします(シミュレーション・プログラムはPython 3.6や3.10では動きません).

$ python --version
3.9.3

サンプルコードの実行に必要なパッケージをインストールします.

$ pip install -r requirements.txt

プログラムの実行方法

シミュレーション・プログラムは次のように実行します.

MacOSの場合

$ python Darwin/syn_pop.py [query] [payment] [function id] [city] [seeds]

Linuxの場合

$ python Linux/syn_pop.py [query] [payment] [function id] [city] [seeds]

Windowsの場合

$ python Windows/syn_pop.py [query] [payment] [function id] [city] [seeds]

なお,それぞれの引数の意味と形式は下の表に整理しています.

引数 意味 値の例
query 支給対象の条件.DataFrameに対するqueryを定義する文字列."" で囲んでください.スペースの入れ方,カンマの入れ方は例のようにしてください. "family_type_id == [0,3,4] and role_household_type_id == [0,1,10,11] and industry_type_id == [-1,130,160] and employment_type_id == [20,30] and company_size_id == [-1,5,10]"
payment 給付金額.float型の金額(単位:万円). 7.5
function id 解(query, payment)を評価する目的関数のidのリスト.""で囲んでください. "[1,2]"
city 都市を表す文字列.naha, hakodateのいずれか. naha
seeds 失業や収入変化における不確実性に関わる乱数シードのリスト.""で囲む. "[123,42,256]"

プログラムの戻り値

プログラムの戻り値は,引数で指定した目的関数の設定により異なることから,注意が必要です. "[1,2]"として$F_1, F_2$共に求めたとき(多目的)には,

[f_1, f_1_list, f_2, f_2_list, feasible, slack_list]

のリストが返されます.このとき,それぞれ以下の意味になります.

  • f_1: $F_1$の目的関数値
  • f_1_list: 各条件で実行した生の$F_1$値(この平均が$F_1$になります)のリスト
  • f_2: $F_2$の目的関数値
  • f_2_list: 各条件で実行した生の$F_2$値(この平均が$F_2$になります)のリスト
  • feasible: 解が支給対象の制約条件を満たすかどうか(TrueFalse
  • slack_list: 各条件で実行したときの制約の上限金額と支給金額との差のリスト.マイナスなら制約を満たしておらず,違反している金額を表す.

なお,解が支給対象の制約条件を満たさない場合には,目的関数値はNoneを返します.

一方,"[2]"として$F_2$のみ求めたとき(単目的)には,

[f_2, f_2_list, judge, slack_list]

のリストが返されます.各条件で実行した生の$F_{1 or 2}$値は,都市セットid(city) -> シナリオid(scenario) -> rnの順番の組合せで,

city = [1, 2, 3]
scenario = ["opt", "mid", "psm"]
rn = [123, 42, 256]

for p in city:
    for s in scenario:
        for r in rn:
            run_simulation(p, s, r)

の順番に計算してリストに値を追加していきます.計算順(追加順)はslack_listも同様です.

実行例

参加者に提供されているローカルでのプログラムの実行例とその結果は以下のようになります.動作確認のためにご参考になさってください.

MacOSの場合

実行例1(単目的の場合):

$ python Darwin/syn_pop.py "family_type_id == [0,3,4,60,70,80] and role_household_type_id == [0,1,21,30,31] and industry_type_id == [-1,10,20,30,50,60,80,90,100,160,170,200] and employment_type_id == [-1,20,30] and company_size_id == [-1,5,10]" 9 "[2]" hakodate "[123,42,256]"

[0.1307580358704799, [0.1313707197856547, 0.1313002026191364, 0.1312634892899727, 0.13088692294228077, 0.13087239002140957, 0.1307946282243626, 0.13066811218344215, 0.1306953866141072, 0.13070710764368682, 0.1314506729512821, 0.13132030517284257, 0.1313647683334795, 0.13094507446588916, 0.13085444934914628, 0.13084794256838034, 0.1307472076752112, 0.13067538296379108, 0.1307000346144736, 0.1307623692517735, 0.13082589235168285, 0.1306699362729692, 0.13025007136648117, 0.13029234923943098, 0.1301422605042281, 0.13000895442703483, 0.13001917353999232, 0.13003116413081547], True, [1159980000.0, 1160250000.0, 1161060000.0, 1156560000.0, 1156920000.0, 1157460000.0, 1155120000.0, 1155120000.0, 1155660000.0, 1161240000.0, 1161420000.0, 1161600000.0, 1157100000.0, 1157460000.0, 1157730000.0, 1155390000.0, 1155930000.0, 1155930000.0, 1178250000.0, 1176720000.0, 1177980000.0, 1175010000.0, 1173480000.0, 1175100000.0, 1173210000.0, 1172580000.0, 1173660000.0]]

実行例2(多目的の場合):

$ python Darwin/syn_pop.py "family_type_id == [0,3,4,60,70,80] and role_household_type_id == [0,1,21,30,31] and industry_type_id == [-1,10,20,30,50,60,80,90,100,160,170,200] and employment_type_id == [-1,20,30] and company_size_id == [-1,5,10]" 9 "[1,2]" naha "[123,42,256]"

[0.9592468031438023, [0.9579048898534249, 0.9579572855666552, 0.9586597565385079, 0.9581159944223518, 0.9588595615816098, 0.958941605839416, 0.9583390693832599, 0.9586432506887052, 0.9590656361351626, 0.9593519780542089, 0.9596038032130593, 0.9598482235253535, 0.9592445670921007, 0.9603285534330729, 0.9601960006211288, 0.9597950946910898, 0.9600524581111628, 0.9602863797118951, 0.9586352916874668, 0.9589904276564976, 0.9596653411144968, 0.959550213528034, 0.959785845857219, 0.9594720176223583, 0.959358270359596, 0.9590927082795532, 0.959919460315275], 0.12241611394380776, [0.12261391778671922, 0.12274120678152665, 0.12282573084392816, 0.12211043588654784, 0.12218305989389748, 0.12224835682441142, 0.12197249826928688, 0.12203904576368052, 0.12209679426785608, 0.12253495895574949, 0.12264328017655984, 0.1225468282642149, 0.12211546715453958, 0.12221635243667135, 0.1222059444307546, 0.1219101127978409, 0.12206923614968941, 0.12190226810229444, 0.12303928784172272, 0.12321123019662898, 0.12306497768610386, 0.12254686404933833, 0.12260967755405938, 0.12264736465772498, 0.12225979297650635, 0.1224983276424315, 0.12238205909212499], True, [2078100000.0, 2076300000.0, 2074590000.0, 2073510000.0, 2071440000.0, 2069370000.0, 2070810000.0, 2068920000.0, 2067210000.0, 2081520000.0, 2078730000.0, 2080350000.0, 2077200000.0, 2074320000.0, 2075040000.0, 2075220000.0, 2071890000.0, 2073330000.0, 2072790000.0, 2069190000.0, 2070000000.0, 2068020000.0, 2064600000.0, 2064510000.0, 2066130000.0, 2062350000.0, 2062350000.0]]

Linuxの場合

実行例1(単目的の場合):

$ python Linux/syn_pop.py "family_type_id == [0,3,4,60,70,80] and role_household_type_id == [0,1,21,30,31] and industry_type_id == [-1,10,20,30,50,60,80,90,100,160,170,200] and employment_type_id == [-1,20,30] and company_size_id == [-1,5,10]" 9 "[2]" hakodate "[123,42,256]"

[0.1307580358704799, [0.1313707197856547, 0.1313002026191364, 0.1312634892899727, 0.13088692294228077, 0.13087239002140957, 0.1307946282243626, 0.13066811218344215, 0.1306953866141072, 0.13070710764368682, 0.1314506729512821, 0.13132030517284257, 0.1313647683334795, 0.13094507446588916, 0.13085444934914628, 0.13084794256838034, 0.1307472076752112, 0.13067538296379108, 0.1307000346144736, 0.1307623692517735, 0.13082589235168285, 0.1306699362729692, 0.13025007136648117, 0.13029234923943098, 0.1301422605042281, 0.13000895442703483, 0.13001917353999232, 0.13003116413081547], True, [1159980000.0, 1160250000.0, 1161060000.0, 1156560000.0, 1156920000.0, 1157460000.0, 1155120000.0, 1155120000.0, 1155660000.0, 1161240000.0, 1161420000.0, 1161600000.0, 1157100000.0, 1157460000.0, 1157730000.0, 1155390000.0, 1155930000.0, 1155930000.0, 1178250000.0, 1176720000.0, 1177980000.0, 1175010000.0, 1173480000.0, 1175100000.0, 1173210000.0, 1172580000.0, 1173660000.0]]

実行例2(多目的の場合):

$ python Linux/syn_pop.py "family_type_id == [0,3,4,60,70,80] and role_household_type_id == [0,1,21,30,31] and industry_type_id == [-1,10,20,30,50,60,80,90,100,160,170,200] and employment_type_id == [-1,20,30] and company_size_id == [-1,5,10]" 9 "[1,2]" naha "[123,42,256]"

[0.9592468031438023, [0.9579048898534249, 0.9579572855666552, 0.9586597565385079, 0.9581159944223518, 0.9588595615816098, 0.958941605839416, 0.9583390693832599, 0.9586432506887052, 0.9590656361351626, 0.9593519780542089, 0.9596038032130593, 0.9598482235253535, 0.9592445670921007, 0.9603285534330729, 0.9601960006211288, 0.9597950946910898, 0.9600524581111628, 0.9602863797118951, 0.9586352916874668, 0.9589904276564976, 0.9596653411144968, 0.959550213528034, 0.959785845857219, 0.9594720176223583, 0.959358270359596, 0.9590927082795532, 0.959919460315275], 0.12241611394380776, [0.12261391778671922, 0.12274120678152665, 0.12282573084392816, 0.12211043588654784, 0.12218305989389748, 0.12224835682441142, 0.12197249826928688, 0.12203904576368052, 0.12209679426785608, 0.12253495895574949, 0.12264328017655984, 0.1225468282642149, 0.12211546715453958, 0.12221635243667135, 0.1222059444307546, 0.1219101127978409, 0.12206923614968941, 0.12190226810229444, 0.12303928784172272, 0.12321123019662898, 0.12306497768610386, 0.12254686404933833, 0.12260967755405938, 0.12264736465772498, 0.12225979297650635, 0.1224983276424315, 0.12238205909212499], True, [2078100000.0, 2076300000.0, 2074590000.0, 2073510000.0, 2071440000.0, 2069370000.0, 2070810000.0, 2068920000.0, 2067210000.0, 2081520000.0, 2078730000.0, 2080350000.0, 2077200000.0, 2074320000.0, 2075040000.0, 2075220000.0, 2071890000.0, 2073330000.0, 2072790000.0, 2069190000.0, 2070000000.0, 2068020000.0, 2064600000.0, 2064510000.0, 2066130000.0, 2062350000.0, 2062350000.0]]

Windowsの場合

実行例1(単目的の場合):

$ python Windows/syn_pop.py "family_type_id == [0,3,4,60,70,80] and role_household_type_id == [0,1,21,30,31] and industry_type_id == [-1,10,20,30,50,60,80,90,100,160,170,200] and employment_type_id == [-1,20,30] and company_size_id == [-1,5,10]" 9 "[2]" hakodate "[123,42,256]"

[0.1307580358704799, [0.1313707197856547, 0.1313002026191364, 0.1312634892899727, 0.13088692294228077, 0.13087239002140957, 0.1307946282243626, 0.13066811218344215, 0.1306953866141072, 0.13070710764368682, 0.1314506729512821, 0.13132030517284257, 0.1313647683334795, 0.13094507446588916, 0.13085444934914628, 0.13084794256838034, 0.1307472076752112, 0.13067538296379108, 0.1307000346144736, 0.1307623692517735, 0.13082589235168285, 0.1306699362729692, 0.13025007136648117, 0.13029234923943098, 0.1301422605042281, 0.13000895442703483, 0.13001917353999232, 0.13003116413081547], True, [1159980000.0, 1160250000.0, 1161060000.0, 1156560000.0, 1156920000.0, 1157460000.0, 1155120000.0, 1155120000.0, 1155660000.0, 1161240000.0, 1161420000.0, 1161600000.0, 1157100000.0, 1157460000.0, 1157730000.0, 1155390000.0, 1155930000.0, 1155930000.0, 1178250000.0, 1176720000.0, 1177980000.0, 1175010000.0, 1173480000.0, 1175100000.0, 1173210000.0, 1172580000.0, 1173660000.0]]

実行例2(多目的の場合):

$ python Windows/syn_pop.py "family_type_id == [0,3,4,60,70,80] and role_household_type_id == [0,1,21,30,31] and industry_type_id == [-1,10,20,30,50,60,80,90,100,160,170,200] and employment_type_id == [-1,20,30] and company_size_id == [-1,5,10]" 9 "[1,2]" naha "[123,42,256]"

[0.9592468031438023, [0.9579048898534249, 0.9579572855666552, 0.9586597565385079, 0.9581159944223518, 0.9588595615816098, 0.958941605839416, 0.9583390693832599, 0.9586432506887052, 0.9590656361351626, 0.9593519780542089, 0.9596038032130593, 0.9598482235253535, 0.9592445670921007, 0.9603285534330729, 0.9601960006211288, 0.9597950946910898, 0.9600524581111628, 0.9602863797118951, 0.9586352916874668, 0.9589904276564976, 0.9596653411144968, 0.959550213528034, 0.959785845857219, 0.9594720176223583, 0.959358270359596, 0.9590927082795532, 0.959919460315275], 0.12241611394380776, [0.12261391778671922, 0.12274120678152665, 0.12282573084392816, 0.12211043588654784, 0.12218305989389748, 0.12224835682441142, 0.12197249826928688, 0.12203904576368052, 0.12209679426785608, 0.12253495895574949, 0.12264328017655984, 0.1225468282642149, 0.12211546715453958, 0.12221635243667135, 0.1222059444307546, 0.1219101127978409, 0.12206923614968941, 0.12190226810229444, 0.12303928784172272, 0.12321123019662898, 0.12306497768610386, 0.12254686404933833, 0.12260967755405938, 0.12264736465772498, 0.12225979297650635, 0.1224983276424315, 0.12238205909212499], True, [2078100000.0, 2076300000.0, 2074590000.0, 2073510000.0, 2071440000.0, 2069370000.0, 2070810000.0, 2068920000.0, 2067210000.0, 2081520000.0, 2078730000.0, 2080350000.0, 2077200000.0, 2074320000.0, 2075040000.0, 2075220000.0, 2071890000.0, 2073330000.0, 2072790000.0, 2069190000.0, 2070000000.0, 2068020000.0, 2064600000.0, 2064510000.0, 2066130000.0, 2062350000.0, 2062350000.0]]

About

EC2021のシミュレーションプログラムとその実行サンプルコードです.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages