前提・実現したいこと
“python”でシフト作成システムを作ろうと思っています。
発生している問題・エラーメッセージ
Traceback (most recent call last): File "kari.py", line 36, in <module> ShiftScheduling += lpSum(x[m, d, a] for m in Member) == n, "Constraint_{:}_{:}".format(d,a) File "/usr/local/lib/python3.7/site-packages/pulp/pulp.py", line 888, in __eq__ return LpConstraint(self - other, const.LpConstraintEQ) File "/usr/local/lib/python3.7/site-packages/pulp/pulp.py", line 809, in __sub__ return self.copy().subInPlace(other) File "/usr/local/lib/python3.7/site-packages/pulp/pulp.py", line 784, in subInPlace self.subInPlace(e) File "/usr/local/lib/python3.7/site-packages/pulp/pulp.py", line 784, in subInPlace self.subInPlace(e) File "/usr/local/lib/python3.7/site-packages/pulp/pulp.py", line 784, in subInPlace self.subInPlace(e) [Previous line repeated 985 more times] File "/usr/local/lib/python3.7/site-packages/pulp/pulp.py", line 782, in subInPlace or isinstance(other, Iterable)): File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/abc.py", line 139, in __instancecheck__ return _abc_instancecheck(cls, instance) RecursionError: maximum recursion depth exceeded in comparison
該当のソースコード
Python
1for d in Day: 2 n = need[d] 3 4for d in Day: 5 for a in Action: 6 ShiftScheduling += lpSum(x[m, d, a] for m in Member) == n, "Constraint_{:}_{:}".format(d,a) 7 8 9ShiftScheduling += lpSum(x[m, d, a] for m in Member) == n, "Constraint_{:}_{:}".format(d,a) 10の部分でエラーが吐かれてます
試したこと
もともとは
Python
1for d in Day: 2 for a in Action: 3 n = need[d] 4 ShiftScheduling += lpSum(x[m, d, a] for m in Member) == n, "Constraint_{:}_{:}".format(d,a) 5
補足情報(FW/ツールのバージョンなど)
途中ですがコードを置きます
Python
1import numpy as np, pandas as pd 2from pulp import * 3 4Member = ["1", "2", "3","4","5","6","7","8","9","10"] 5Day = ["11", "12", "13", "14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","1","2","3","4","5","6","7","8","9","10"] 6Action = ["出勤", "休み"] 7 8#問題の宣言 9ShiftScheduling = LpProblem("ShiftScheduling", LpMinimize) 10 11#変数宣言 12x = {} 13for m in Member: 14 for d in Day: 15 for a in Action: 16 x[m, d, a] = LpVariable('x({:},{:},{:})'.format(m,d,a), 0, 1, LpInteger)#バイナリ 17 18days_counter = {} 19six_counter = {} 20for m in Member: 21 days_counter[m] = LpVariable('days_counter({:})'.format(m), 0, 7, LpInteger)#連続出勤回数 22 six_counter[m] = LpVariable('six_counter({:})'.format(m), 0, 6, LpInteger)#6連勤の回数 23 24need = {} 25for d in Day: 26 need[d] = input(d+"日に必要な人数を入力してください。") 27 28#目的関数:全体の6連勤の数を減らす 29ShiftScheduling += lpSum(six_counter[m] for m in Member), "Target" 30 31# それぞれの日の朝やお迎えに必ず誰か1人が割り当てられる 32for d in Day: 33 n = need[d] 34 35for d in Day: 36 for a in Action: 37 ShiftScheduling += lpSum(x[m, d, a] for m in Member) == n, "Constraint_{:}_{:}".format(d,a) 38 39results = ShiftScheduling.solve() 40print("optimality = {:}, target value = {:}".format(LpStatus[results], value(ShiftScheduling.objective))) 41 42 43for m in Member: 44 for d in Day: 45 for a in Action: 46 if value(x[m,d,a]) == 1: 47 print(value(x[m,d,a])) 48 print(x[m,d,a]) 49 50o ={} 51for d in Day: 52 for a in Action: 53 for m in Member: 54 if value(x[m,d,a]) == 1: 55 o.setdefault(d,[]).append(m) 56 57print(o) 58 59print(pd.DataFrame(n,index = ['出勤','休み']))
回答3件
あなたの回答
tips
プレビュー