Skip to content

Commit

Permalink
implement normalized multiplicative update in PADM
Browse files Browse the repository at this point in the history
  • Loading branch information
hlefebvr committed Oct 11, 2024
1 parent e5dcb7d commit df60d4f
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ class idol::ADM::Formulation {
void initialize_penalty_parameters(double t_value);

void update_penalty_parameters(const std::vector<Solution::Primal>& t_primals, PenaltyUpdate& t_penalty_update);

struct CurrentPenalty {
Ctr constraint;
Var variable;
double max_violation;
double penalty;
CurrentPenalty(Ctr t_constraint, Var t_variable, double t_max_violation, double t_penalty)
: constraint(std::move(t_constraint)), variable(t_variable), max_violation(t_max_violation), penalty(t_penalty) {}
};

private:
Annotation<Var, unsigned int> m_decomposition;
std::optional<Annotation<Ctr, bool>> m_penalized_constraints;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#ifndef IDOL_PENALTYUPDATES_H
#define IDOL_PENALTYUPDATES_H

#include <list>
#include "Formulation.h"

namespace idol {
class PenaltyUpdate;

Expand All @@ -20,6 +23,8 @@ class idol::PenaltyUpdate {

virtual double operator()(double t_current_penalty) = 0;

virtual void operator()(std::list<ADM::Formulation::CurrentPenalty>& t_current_penalties);

virtual PenaltyUpdate* clone() const = 0;
};

Expand All @@ -39,13 +44,16 @@ class idol::PenaltyUpdates::Additive : public PenaltyUpdate {

class idol::PenaltyUpdates::Multiplicative : public PenaltyUpdate {
double m_factor;
bool m_normalized;
public:
explicit Multiplicative(double t_factor) : m_factor(t_factor) {}
explicit Multiplicative(double t_factor, bool t_normalized = false) : m_factor(t_factor), m_normalized(t_normalized) {}

double operator()(double t_current_penalty) override {
return t_current_penalty * m_factor;
}

void operator()(std::list<ADM::Formulation::CurrentPenalty> &t_current_penalties) override;

PenaltyUpdate* clone() const override {
return new Multiplicative(*this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ idol::ADM::Formulation::update_penalty_parameters(const std::vector<Solution::Pr
return;
}

std::list<CurrentPenalty> current_penalties;

for (auto &[ctr, penalty]: m_l1_vars) {

auto &[var, value] = penalty;
Expand All @@ -327,9 +329,13 @@ idol::ADM::Formulation::update_penalty_parameters(const std::vector<Solution::Pr
continue;
}

value = t_penalty_update(value);
set_penalty_in_all_sub_problems(var, value);
current_penalties.emplace_back(ctr, var, max, value);

}

t_penalty_update(current_penalties);
for (const auto& [ctr, var, violation, penalty] : current_penalties) {
set_penalty_in_all_sub_problems(var, penalty);
}

if (m_rescaling.first) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,30 @@
//

#include "idol/optimizers/mixed-integer-optimization/padm/PenaltyUpdates.h"

void idol::PenaltyUpdate::operator()(std::list<ADM::Formulation::CurrentPenalty> &t_current_penalties) {

for (auto& penalty : t_current_penalties) {
penalty.penalty = (*this)(penalty.penalty);
}

}

void
idol::PenaltyUpdates::Multiplicative::operator()(std::list<ADM::Formulation::CurrentPenalty> &t_current_penalties) {

if (!m_normalized) {
PenaltyUpdate::operator()(t_current_penalties);
}

double max_violation = 0;
for (const auto& penalty : t_current_penalties) {
max_violation = std::max(max_violation, penalty.max_violation);
}

// scales the factor from 1 to m_factor
for (auto& penalty : t_current_penalties) {
penalty.penalty = 1 + (m_factor - 1.) * penalty.max_violation / max_violation;
}

}

0 comments on commit df60d4f

Please sign in to comment.