PuLP - adding conditional constrain for optimization

35 Views Asked by At

I am working on an optimization model using Pyomo where I need to calculate the total exposure of loans, but only include the loans that have already started. The challenge is to write a constraint that calculates the total exposure for a specific week, incorporating only the loans that are active in that week.

The model has the following components:

model.loan_amount[i]: The amount of loan i.
model.start_week[i]: The week when loan i starts.
model.loan_duration[i]: The duration of repaymen of loan i in weeks.
model.weeks: A set of all weeks.
max_exposure: A parameter representing the maximum allowed exposure for a week.

I'm trying to write a constraint (exposure_rule) that sums up the amounts of active loans for each week without violating the maximum exposure limit. Here's my current attempt:

    def exposure_rule(model, week):
       total_exposure = sum(
          # if week >= model.start_week[i] and week < model.start_week[i] + model.loan_duration[i]
          model.loan_amount[i] - (week - model.start_week[i]) * model.repayment_per_week[i]
          # else 0
          for i in model.loans
        )
       return total_exposure <= max_exposure

    model.ExposureConstraint = Constraint(model.weeks, rule=exposure_rule)

but i cant have a conditional variable in the constraint

I tried to use binary var and inequality

0

There are 0 best solutions below