Skip to content

Instantly share code, notes, and snippets.

@FabulousCupcake
Last active March 28, 2023 14:37
Show Gist options
  • Save FabulousCupcake/9f81b87c71ec352a15aaa89f6397c4b2 to your computer and use it in GitHub Desktop.
Save FabulousCupcake/9f81b87c71ec352a15aaa89f6397c4b2 to your computer and use it in GitHub Desktop.
Blue Archive Optimal Event Farming Problem
!pip install pulp
from pulp import *
from math import ceil
# 1-3 Materials, 4 Event Points
# INPUT Material Multipliers
m1mult = 2.0
m2mult = 1.7
m3mult = 1.7
m4mult = 1.6
# INPUT Required Materials
m1req = 13670
m2req = 11680
m3req = 5900
m4req = 15000
# INPUT Already Obtained Materials
m1hav = 1282
m2hav = 1057
m3hav = 924
m4hav = 1998
# INPUT Stage Loots
s09rawLoots = [40, 0, 0, 8]
s10rawLoots = [0, 32, 0, 8]
s11rawLoots = [0, 0, 27, 8]
s12rawLoots = [6, 6, 6, 32]
# Compute actual materials needed
m1need = m1req - m1hav
m2need = m2req - m2hav
m3need = m3req - m3hav
m4need = m4req - m4hav
# Compute multiplied stage loots
mult = [m1mult, m2mult, m3mult, m4mult]
s09l = [ceil(s09rawLoots[i] * mult[i]) for i in range(0,4)]
s10l = [ceil(s10rawLoots[i] * mult[i]) for i in range(0,4)]
s11l = [ceil(s11rawLoots[i] * mult[i]) for i in range(0,4)]
s12l = [ceil(s12rawLoots[i] * mult[i]) for i in range(0,4)]
# Initialize Pulp
prob = LpProblem("BlueArchiveEventProblem", LpMinimize)
s09 = LpVariable("Stage 9", 0, None, LpInteger)
s10 = LpVariable("Stage 10", 0, None, LpInteger)
s11 = LpVariable("Stage 11", 0, None, LpInteger)
s12 = LpVariable("Stage 12", 0, None, LpInteger)
# Solve for the minimum number of runs
prob += s09 + s10 + s11 + s12
# Define constraints
prob += m1need <= (s09*s09l[0] + s10*s10l[0] + s11*s11l[0] + s12*s12l[0])
prob += m2need <= (s09*s09l[1] + s10*s10l[1] + s11*s11l[1] + s12*s12l[1])
prob += m3need <= (s09*s09l[2] + s10*s10l[2] + s11*s11l[2] + s12*s12l[2])
prob += m4need <= (s09*s09l[3] + s10*s10l[3] + s11*s11l[3] + s12*s12l[3])
prob.solve()
print(f"With...")
print(f"Stage 09 yielding {s09l}")
print(f"Stage 10 yielding {s10l}")
print(f"Stage 11 yielding {s11l}")
print(f"Stage 12 yielding {s12l}")
print()
print(f"To obtain...")
print(f"{m1req} - {m1hav} = {m1need} Material 1")
print(f"{m2req} - {m2hav} = {m2need} Material 2")
print(f"{m3req} - {m3hav} = {m3need} Material 3")
print(f"{m4req} - {m4hav} = {m4need} Material 4")
print()
print(f"The minimum combination number of runs required is the following:")
print(f"Stage 09: {ceil(value(s09))} runs")
print(f"Stage 10: {ceil(value(s10))} runs")
print(f"Stage 11: {ceil(value(s11))} runs")
print(f"Stage 12: {ceil(value(s12))} runs")
print(f" Total: {ceil(value(s09+s10+s11+s12))} runs")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment