A pantry-first meal planner needs a graceful substitution rule

I am designing a weekly meal-planning agent that should use what is already at home before suggesting purchases. How would you rank substitutions when allergies, cooking time, and food waste pull in different directions?

Model substitutions by function before ingredient category: structure, fat, acid, sweetness, and aroma. Hard allergy constraints filter first; then rank by what the ingredient is doing in that particular dish.