Skip to content

Commit

Permalink
#696 不养闲人优化
Browse files Browse the repository at this point in the history
  • Loading branch information
Shawnsdaddy committed Oct 6, 2024
1 parent 76dac16 commit de7a60d
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
4 changes: 3 additions & 1 deletion arknights_mower/solvers/base_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ def plan_metadata(self):
if _idx is not None:
__type.append("dorm" + str(_idx))
planned_index.append(_idx)
logger.debug(f"计划干员为{x}")
__room = self.op_data.operators[x].room
if __room not in __plan.keys():
__plan[__room] = ["Current"] * len(self.op_data.plan[__room])
Expand Down Expand Up @@ -851,7 +852,6 @@ def agent_get_mood(self, skip_dorm=False, force=False):
for item in _mood_data
]
logger.info(f"房间 {self.translate_room(room)} {mood_info}")
# logger.info(f'房间 {room} 心情为:{_mood_data}')
break
except MowerExit:
raise
Expand Down Expand Up @@ -1466,6 +1466,8 @@ def plan_solver(self):
return
if self.agent_get_mood() is None:
self.backup_plan_solver()
if not self.find_next_task(datetime.now() + timedelta(minutes=5)):
try_add_release_dorm({}, None, self.op_data, self.tasks)

def backup_plan_solver(self, timing=None):
if timing is None:
Expand Down
5 changes: 4 additions & 1 deletion arknights_mower/utils/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,9 @@ def init_mood_limit(self):

def evaluate_expression(self, expression):
try:
result = Expr(expression, self.eval_model).eval({"op_data": self})
model = {e: e for e in base_room_list}
model["op_data"] = self
result = Expr(expression, self.eval_model).eval(model)
return result
except Exception as e:
logger.exception(f"Error evaluating expression: {e}")
Expand Down Expand Up @@ -513,6 +515,7 @@ def correct_dorm(self):
):
op.mood = op.upper_limit
op.time_stamp = self.dorm[idx].time
op.depletion_rate = 0
logger.debug(
f"检测到{op.name}心情恢复满,设置心情至{op.upper_limit}"
)
Expand Down
50 changes: 50 additions & 0 deletions arknights_mower/utils/scheduler_task.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import copy
import heapq
from datetime import datetime, timedelta
from enum import Enum
from typing import Literal
Expand Down Expand Up @@ -171,12 +172,61 @@ def scheduling(tasks, run_order_delay=5, execution_time=0.75, time_now=None):
def try_add_release_dorm(plan, time, op_data, tasks):
if not op_data.config.free_room:
return
# 有plan 的情况
for k, v in plan.items():
for name in v:
if name != "Current":
_idx, __dorm = op_data.get_dorm_by_name(name)
if __dorm and __dorm.time < time:
add_release_dorm(tasks, op_data, name)
# 普通情况
if not plan:
try:
# 查看是否有未满心情的人
logger.info("启动不养闲人安排空余宿舍位")
waiting_list = []
for k, v in op_data.operators.items():
if (
not v.is_high()
and v.current_mood() < v.upper_limit
and v.current_room == ""
and v.name not in op_data.free_blacklist
):
heapq.heappush(
waiting_list,
(
1 if k in ["九色鹿", "年"] else 0,
(v.current_mood() - v.lower_limit)
/ (v.upper_limit - v.lower_limit),
k,
),
)
logger.debug(f"{k}:心情:{v.current_mood()}")
if not waiting_list:
return
logger.debug(f"有{len(waiting_list)}个干员心情未满")
plan = {}
for idx, value in enumerate(op_data.dorm):
if value.name in op_data.operators:
if not waiting_list:
break
agent = op_data.operators[value.name]
logger.info(str(value))
if not v.is_high() and (
agent.current_mood() >= agent.upper_limit
or (value.time is not None and value.time < datetime.now())
):
rest = heapq.heappop(waiting_list)
if value.position[0] not in plan:
plan[value.position[0]] = ["Current"] * 5
plan[value.position[0]][value.position[1]] = rest[2]
if plan:
logger.debug(f"不养闲人任务:{plan}")
logger.info("添加不养闲人任务完成")
task = SchedulerTask(task_plan=plan)
tasks.append(task)
except Exception as ex:
logger.exception(ex)


def add_release_dorm(tasks, op_data, name):
Expand Down

0 comments on commit de7a60d

Please sign in to comment.