Pipal  1.2.0
Penalty Interior-Point ALgorithm
Loading...
Searching...
No Matches
Input.hxx
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
2 * Copyright (c) 2025, Davide Stocco and Enrico Bertolazzi. *
3 * *
4 * The Pipal project is distributed under the MIT License. *
5 * *
6 * Davide Stocco Enrico Bertolazzi *
7 * University of Trento University of Trento *
8 * e-mail: davide.stocco@unitn.it e-mail: enrico.bertolazzi@unitn.it *
9\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
10
11#pragma once
12
13#ifndef INCLUDE_PIPAL_INPUT_HXX
14#define INCLUDE_PIPAL_INPUT_HXX
15
16namespace Pipal
17{
28 template <typename Real>
29 void Solver<Real>::buildInput(std::string const & name, Vector<Real> const & x0, Vector<Real> const & bl,
30 Vector<Real> const & bu, Vector<Real> const & cl, Vector<Real> const & cu)
31 {
32 // Create alias for easier access
34 Input<Real> & i{this->m_input};
35
36 // Set problem identity
37 i.name = name;
38
39 // Set number of original formulation variables
40 i.n0 = static_cast<Integer>(x0.size());
41
42 // Find indices sets
43 static constexpr Real EPSILON{std::numeric_limits<Real>::epsilon()};
44 Mask const cond_bl(bl.array() <= -p.rhs_bnd);
45 Mask const cond_bu(bu.array() >= p.rhs_bnd);
46 Mask const cond_cl(cl.array() <= -p.rhs_bnd);
47 Mask const cond_cu(cu.array() >= p.rhs_bnd);
48 Mask const cond_beq((bl.array() - bu.array()).abs() <= EPSILON);
49 Mask const cond_ceq((cl.array() - cu.array()).abs() <= EPSILON);
50
51 // Now the index sets
52 i.I1 = find(cond_bl && cond_bu);
53 i.I2 = find(cond_beq);
54 i.I3 = find(!cond_bl && cond_bu);
55 i.I4 = find(cond_bl && !cond_bu);
56 i.I5 = find(!cond_bl && !cond_bu && !cond_beq);
57 i.I6 = find(cond_ceq);
58 i.I7 = find(!cond_cl && cond_cu);
59 i.I8 = find(cond_cl && !cond_cu);
60 i.I9 = find(!cond_cl && !cond_cu && !cond_ceq);
61
62 // Set right-hand side values
63 i.b2 = bl(i.I2);
64 i.l3 = bl(i.I3);
65 i.u4 = bu(i.I4);
66 i.l5 = bl(i.I5);
67 i.u5 = bu(i.I5);
68 i.b6 = cl(i.I6);
69 i.l7 = cl(i.I7);
70 i.u8 = cu(i.I8);
71 i.l9 = cl(i.I9);
72 i.u9 = cu(i.I9);
73
74 // Set sizes of indices sets
75 i.n1 = static_cast<Integer>(i.I1.size());
76 i.n2 = static_cast<Integer>(i.I2.size());
77 i.n3 = static_cast<Integer>(i.I3.size());
78 i.n4 = static_cast<Integer>(i.I4.size());
79 i.n5 = static_cast<Integer>(i.I5.size());
80 i.n6 = static_cast<Integer>(i.I6.size());
81 i.n7 = static_cast<Integer>(i.I7.size());
82 i.n8 = static_cast<Integer>(i.I8.size());
83 i.n9 = static_cast<Integer>(i.I9.size());
84
85 // Initialize number of invalid bounds
86 i.vi = 0;
87
88 // Count invalid bounds
89 if (i.n2 > 0) {
90 i.vi += (i.b2.array() <= -p.rhs_bnd).count();
91 i.vi += (i.b2.array() >= p.rhs_bnd).count();
92 }
93 if (i.n3 > 0) {
94 i.vi += (i.l3.array() >= p.rhs_bnd).count();
95 }
96 if (i.n4 > 0) {
97 i.vi += (i.u4.array() <= -p.rhs_bnd).count();
98 }
99 if (i.n5 > 0) {
100 i.vi += (i.l5.array() >= p.rhs_bnd).count();
101 i.vi += (i.u5.array() <= -p.rhs_bnd).count();
102 i.vi += (i.l5.array() > i.u5.array()).count();
103 }
104 if (i.n6 > 0) {
105 i.vi += (i.b6.array() <= -p.rhs_bnd).count();
106 i.vi += (i.b6.array() >= p.rhs_bnd).count();
107 }
108 if (i.n7 > 0) {
109 i.vi += (i.l7.array() >= p.rhs_bnd).count();
110 }
111 if (i.n8 > 0) {
112 i.vi += (i.u8.array() <= -p.rhs_bnd).count();
113 }
114 if (i.n9 > 0) {
115 i.vi += (i.l9.array() >= p.rhs_bnd).count();
116 i.vi += (i.u9.array() <= -p.rhs_bnd).count();
117 i.vi += (i.l9.array() > i.u9.array()).count();
118 }
119
120 // Set number of variables and constraints
121 i.nV = i.n1 + i.n3 + i.n4 + i.n5;
122 i.nI = i.n3 + i.n4 + 2*i.n5 + i.n7 + i.n8 + 2*i.n9;
123 i.nE = i.n6;
124
125 // Set size of primal-dual matrix
126 i.nA = i.nV + 3*i.nE + 3*i.nI;
127
128 // Set initial point
129 i.x0.resize(i.nV);
130 i.x0 << x0(i.I1), x0(i.I3), x0(i.I4), x0(i.I5);
131 }
132
133} // namespace Pipal
134
135#endif // INCLUDE_PIPAL_INPUT_HXX
void buildInput(std::string const &name, Vector< Real > const &x0, Vector< Real > const &bl, Vector< Real > const &bu, Vector< Real > const &cl, Vector< Real > const &cu)
Build the input data for the solver.
Definition Input.hxx:29
Input< Real > m_input
Definition Solver.hxx:44
Parameter< Real > m_parameter
Definition Solver.hxx:48
Namespace for the Pipal library.
Definition Acceptance.hxx:16
static Indices find(Mask const &mask)
Select elements from a vector based on a boolean mask.
Definition Types.hxx:133
PIPAL_DEFAULT_INTEGER_TYPE Integer
The Integer type as used for the API.
Definition Types.hxx:110
Eigen::Array< bool, Eigen::Dynamic, 1 > Mask
Definition Types.hxx:118
Eigen::Vector< Real, Eigen::Dynamic > Vector
Definition Types.hxx:112
Input structure holding all the data defining the optimization problem.
Definition Types.hxx:316
Vector< Real > l3
Definition Types.hxx:329
Indices I1
Definition Types.hxx:318
Vector< Real > l9
Definition Types.hxx:336
Vector< Real > l5
Definition Types.hxx:331
Integer nV
Definition Types.hxx:348
std::string name
Definition Types.hxx:317
Integer n3
Definition Types.hxx:341
Integer n4
Definition Types.hxx:342
Indices I7
Definition Types.hxx:324
Integer n5
Definition Types.hxx:343
Integer n1
Definition Types.hxx:339
Integer n6
Definition Types.hxx:344
Integer n9
Definition Types.hxx:347
Indices I3
Definition Types.hxx:320
Vector< Real > u9
Definition Types.hxx:337
Vector< Real > b6
Definition Types.hxx:333
Indices I6
Definition Types.hxx:323
Integer nA
Definition Types.hxx:351
Vector< Real > u5
Definition Types.hxx:332
Integer n0
Definition Types.hxx:338
Indices I4
Definition Types.hxx:321
Indices I9
Definition Types.hxx:326
Indices I2
Definition Types.hxx:319
Indices I8
Definition Types.hxx:325
Integer n7
Definition Types.hxx:345
Integer n8
Definition Types.hxx:346
Integer nI
Definition Types.hxx:349
Vector< Real > x0
Definition Types.hxx:327
Vector< Real > l7
Definition Types.hxx:334
Indices I5
Definition Types.hxx:322
Integer n2
Definition Types.hxx:340
Integer nE
Definition Types.hxx:350
Integer vi
Definition Types.hxx:352
Vector< Real > u4
Definition Types.hxx:330
Vector< Real > b2
Definition Types.hxx:328
Vector< Real > u8
Definition Types.hxx:335
Internal parameters for the solver algorithm.
Definition Types.hxx:229
static constexpr Real rhs_bnd
Definition Types.hxx:230