  Black soldier fly (BSF) larvae (\textit{Hermetia illucens}) are a valuable
protein source for manufacturing animal feed. To maximize their production,
both the quantity and quality of their reproductive cycle, i.e. egg production
during oviposition, must be increased. In artificial environments, flies often
sit idle in cages without mating, depleting their energy reserves and resulting
in lower egg production per female.
  By controlling environmental conditions such as temperature and light inside
breeding cages, the flies may be stimulated in a way that improves egg output.
However, this stimulation increases the energy demand of the process and may
stress the flies, resulting in reduced egg production. Therefore, control must
be applied in a careful way, which requires knowledge of the egg production
cycle.
  In this work, a mathematical model describing the various fly life stages and
their transition to the egg production process is developed. Relevant factors
are identified and their effect on the fly life and egg production is
mathematically described. Parameters are identified using data from literature
and goodness of fit is evaluated. Using the model, an optimal control problem
is formulated with the goal of minimizing the energy costs and increasing the
egg production quantity. In Simulation, our approach showed 13\% higher output
in shorter time at reduced energy costs compared to a (standard) constant
setpoint approach. Optimal control could reach same amount of egg in 60~\% of
time compared to standard scenario.
