Non-convergent "weighted" objective function

rocco_sprmnt21
Tue, 30 Sep 2025 11:27:16 +0000
Optimization (Mathematical)

I need to find a way to allocate a pool of resources to perform a series of daily services over the course of a month.
There are obviously a long series of general (for all resources) and specific (for individual resources) constraints.
The objective function to be minimized tries to make the assignment “balanced.”
Using HIGHS, I can’t use quadratic functions, but I approximate the result by adding two auxiliary variables (lower_bound=m and upper_bound=M) and imposing Min(M-m).
The script converges quickly and provides a result.

...
model = Model(HiGHS.Optimizer)
#set_silent(model)
@variable(model, x[1:nr, 1:ng, turni ], Bin)
@variable(model, z[1:nr, 1:ng], Bin)
@constraints(model, begin

    # each day must have exactly one Ti or one Fi
    fer1[k in union(t_feriali,t_card), g in g_feriali], sum(x[:,g,k]) == 1
    fer2[k in t_festivi, g in g_feriali], sum(x[:,g,k]) == 0

    fest1[k in t_festivi, g in g_festivi], sum(x[:,g,k]) == 1
    fest2[k in union(t_feriali, t_card), g in g_festivi], sum(x[:,g,k]) == 0

    sat[k in t_Cs, g in saturdays(mese,y)], sum(x[:,g,k]) == 1
    no_sat[k in ["CUMs","CLMs"], g in setdiff(1:ng,saturdays(mese,y))], sum(x[:,g,k]) == 0
...

    # no more than 5 turni consecutive
    [r in 1:nr, g in 6:ng], sum(sum(x[r,i,k] for k in turni ) for i in g-5:g) <= 5


    # nothing can follow N or NF
     [r in 1:nr, g in 2:ng, k in turni], x[r,g,k] <= 1 - x[r,g-1,"NF"]
     [r in 1:nr, g in 2:ng, k in turni], x[r,g,k] <= 1 - x[r,g-1,"N"]

    #distance between N and N or NF >=4
     [r in 1:nr, g in 5:ng], sum(x[r,i,"N"]+x[r,i,"NF"] for i in g-4:g) <= 1

end)


peso = Dict{Int, Float64}()
for g in g_festivi
        peso[g] = 1.5
end
for g in g_feriali
        peso[g] = 1.0
end


# Carico di lavoro
@expression(model, workload[r=no_E], sum(x[r, g,k]*peso[g] for g in 1:ng, k in turni))

# Variabili per max/min carico
@variable(model, M)   # massimo carico
@variable(model, m)   # minimo carico

@constraint(model, [r in no_E], workload[r] <= M)
@constraint(model, [r in no_E], workload[r] >= m)

# Obiettivo: minimizzare squilibrio massimo
@objective(model, Min, M - m)
...

To obtain a more “fair” result, I tried solving the same problem by assigning different weights to some days of the month.
In this form, I obtain an “infinite” sequence of the following lines:

How can I read this output?
Can you give me some general suggestions for overcoming this problem?
If needed, I can post the complete script.

17 posts - 3 participants