As I understand we should put a slack variable to match an inequality constraint by inserting the variable slack on the side that is less than the other side, for example if we have 4x + 2 <2 this will be 4x + 2 + variable_slack = 2. But here on Wikipedia:
https://en.wikipedia.org/wiki/Slack_variable
In the example section it says the following "By entering the slack variable y> = 0, the inequality Ax <= b can be converted to the equation yAx + b = 0", which means that the slack variable inserted on the larger side! Please someone explain this confusion.
Tag: Optimization
mathematical optimization – Iterate Minimize in a list of functions
I have a function $ f $ defined in $ ( 1,1) $.
For a minimal example, it is sufficient to define
f(z_):=z^2  1
I need to find a list of points so that $ f (z_0) = f (z_1) $, points whose image "is at the same height".
I continued to find the minimum through
min = First@Minimize(f(z), {z})
what happens for $ z $ equal to
argmin = Values@Last@Minimize(f(z), {z})
Also I created a list with
rang = Subdivide(a, 0,10)
spanning the range from minimum to predefined value.
Now I would like to find, for each item on this list, points such that $ f (z_0) = f (z_1) = rang_j $, for each item in the list.
I couldn't find a better plan than defining a list of features $ fun_j = (f (z) + rang_j) ^ 2 $. By changing the original function and squaring, I am sure that the functions $ fun_j $, one for each item in the list $ rang $ they are positive everywhere except the roots.
So I wanted to iterate over the list of functions a restricted minimization through the commands (the argument $ f_j $ just to clarify my question, I understand that the syntax will be different, that's exactly what the question is about):
Minimize({f_j, z > argmin}, {z})
Minimize({f_j, z > argmin}, {z})
that is, run two minimizations one on the left and one on the right of the $ {arg , min} $. I know for mathematical reasons that there are two unique solutions.
I create my list of functions as
f1(z_,c_):=f(z)+c
and then using
f1(z,rang)
but I find it hard to iterate Minimize, any suggestion would be helpful.
Annoying
Minimize({f1( z, rang), z > b}, z)
produces an error message, since the Minimize function argument is expected to be a scalar function.
I'd also like to hear about better methods, in general and in reference to Mathematica.
Health
mathematical optimization: fitting experimental data to the SRK equation of state. Minimization
I am trying to find parameters to adjust an EoS to saturation pressures at different temperatures.
My experimental data is like this
psatx={{Temperature1,Pressure1,Uncertainty1},{T2,p2,u2},....}
Then I defined a function to calculate saturation pressures
psat(T_, p0_, Tc_, a0_, b_, c1_, E11r_, v11_) := (Do(
p(0) = p0;
f11 = Exp(E11r/T)  1;
m11 = v11*f11;
a = a0*(1 + c1*(1  Sqrt(T/Tc)))^2;
(Alpha) = p(i)*a/(R*T)^2; (* Dimensionless groups*)
(Beta) = p(i)*b/R/T;
(Gamma) = p(i)*m11/R/T;
d0 = (Gamma)*(Beta)*((Beta) + (Alpha));(*Coefficients of the equation*)
d1 = (Alpha)*((Gamma)  (Beta))  (Beta)*(Gamma)*(1 + (Beta));
d2 = (Alpha)  (Beta)*(1 + (Beta));
d3 = (Gamma)  1;
d4 = 1;
polin = d4*z^4 + d3*z^3 + d2*z^2 + d1*z + d0;
Raices = NSolve(polin == 0, z, PositiveReals); (* Solving the 4th grade polinomy for compressibility factor*)
zv = Max(z /. Raices);
zl = Min(z /. Raices);
vv = zv*R*T/p(i);
vl = zl*R*T/p(i);
ln(CapitalPhi)v =
zv  1  Log(zv) + Log(vv/(vv  b)) + a/b/R/T*Log(vv/(vv + b)) +
Log(vv/(vv + m11)); (*Fugacity coefficients*)
ln(CapitalPhi)l =
zl  1  Log(zl) + Log(vl/(vl  b)) + a/b/R/T*Log(vl/(vl + b)) +
Log(vl/(vl + m11));
(CapitalPhi)v = Exp(ln(CapitalPhi)v);
(CapitalPhi)l = Exp(ln(CapitalPhi)l);
p(i + 1) = p(i)*(CapitalPhi)l/(CapitalPhi)v,
{i, 0, 9});
p(9))
Where T is the temperature p0 is the initial pressure assumption, Tc is the critical temperature and a0, b, c1, E11r, v11 are the parameters of the equation.
Up to this point, we have a saturation pressure calculator, given the parameters, and it works fine, now what I can't seem to solve is fitting it to my experimental data, minimizing an objective function, which is:
I said it like this:
F(a0_, b_, c1_, E11r_, v11_) :=
Sum((psat(psatx((k, 1)), psatx((k, 2)), Tcaceto, a0, b, c1, E11r,
v11)  psatx((k, 2)))^2/psatx((k, 3))^2, {k, 200});
(* I declared the Tc as "Tcaceto", a constant, and I use as initial guess for each psat calculation the experimental pressure*)
And then I just used NMinimize, In this way.
NMinimize(F(a0, b, c1, E11r, v11), {a0, b, c1, E11r, v11})
I run it, and it never ends. I don't know what might not be working, I have tried to configure the method, the starting points, but the result is the same. I would really appreciate someone to help me on this matter. Thank you.
optimization – How can I vectorize and optimize function in c to get random numbers?
I programmed a function that generates random numbers.
However, I can't get my compiler to vectorize this function.
How can I transform this function so that my compiler can vectorize it and to reduce the program's execution time?
unsigned int seed;
unsigned int temp;
#define val13 13
unsigned int var1 = 214013;
unsigned int var2 = 2531011;
inline int myRandom() {
temp = var1*seed;
seed = temp + var2;
return (seed>>val13);
}
What are onpage and offpage optimization?
What are optimizations on and off the page?
oc.optimization and control – Pros and cons of using integer programming alone or integer global and global optimization?
First, I'm not sure if this is the right question in this forum. But I have been looking for answers for a long time and I have also been asking the "engineering" professors of my university, but it seems that I do not get a mathematical answer.
I am trying to solve a complex optimization problem involving network and short path optimization while solving nonlinear pressure, fluxes, and diameter. I can apply one of the following methods:

The first method is to use a mixed integer linear programming method.
(MILP) alone and linearizes pressure, flows and diameter using
piecewise linear approximation. Linearization is performed from the
MILP only takes linear equations and looks for an optimal solution. 
The second method is to use global and combined local optimization
optimization method Local optimization would use MILP first to
find solution to subproblems where continuous optimization would be
expensive to use (eg production allocation). So, I would use a
global optimization method using genetic algorithm without derivative
disturb the system (for example, the network path) and
find a better global solution. Every time the system is disturbed,
Local MILP optimization is repeated.
I am behind any recommendation, notice and things to keep in mind if I implement one of these two methods. Is the second method mathematically acceptable compared to the first method?
magento2: indexing optimization catalogrule_product_price
We have a situation where catalogrule_product_price
The table has around 13,000,000 rows.
Indexing is time consuming and the main goal is to speed it up and leave more resources for the server.
The greatest success comes from websites and customer groups (52 of them currently and on the rise).
I was wondering if it would be considerable / feasible to make Magento believe it only has one group of clients (0) regarding indexing.
Somehow take advantage of the logic that every time you try to loop through the customer groups to index, you get a fixed group (0). And every time you try to charge the price from catalogrule_product_price
table based on the customer_group_id
, you would be forced to request the price for the fixed group ID (0).
That idea came about as we know that custom pricing will not be used for customer groups. Theoretically, the logic could be extended to have a setting at the customer group level, which defines whether this specific customer group should be included for indexing (which would be selected if this group actually got a special price rule).
Or is there any other alternative to do it faster?
optimization – Optimize SELECT statement for mysql database
I have this query:
SELECT COUNT(*) AS "Other"
FROM events
JOIN triggers ON events.objectid = triggers.triggerid
WHERE events.name REGEXP "No data from SAM0056(.FTG.REC.LEFT.RIGHT.BACK), .* offline"
AND events.value = 1
AND triggers.value = 1;
Altogether I need to execute 32 variants of these queries depending on REGEXP. And I also need to run these queries every 15. So I have a lot of select statements. How can I optimize the database for these queries?
In this case, should I create indexes and on which tables? These are the tables involved (events and triggers):
 Table  Non_unique  Key_name  Seq_in_index  Column_name  Collation  Cardinality  Sub_part  Packed  Null  Index_type  Comment  Index_comment 
++++++++++++++
 events  0  PRIMARY  1  eventid  A  7633  NULL  NULL   BTREE   
 events  1  events_1  1  source  A  2  NULL  NULL   BTREE   
 events  1  events_1  2  object  A  2  NULL  NULL   BTREE   
 events  1  events_1  3  objectid  A  954  NULL  NULL   BTREE   
 events  1  events_1  4  clock  A  7633  NULL  NULL   BTREE   
 events  1  events_2  1  source  A  2  NULL  NULL   BTREE   
 events  1  events_2  2  object  A  2  NULL  NULL   BTREE   
 events  1  events_2  3  clock  A  7633  NULL  NULL   BTREE   
++++++++++++++
Y
 Table  Non_unique  Key_name  Seq_in_index  Column_name  Collation  Cardinality  Sub_part  Packed  Null  Index_type  Comment  Index_comment 
++++++++++++++
 triggers  0  PRIMARY  1  triggerid  A  1826  NULL  NULL   BTREE   
 triggers  1  triggers_1  1  status  A  4  NULL  NULL   BTREE   
 triggers  1  triggers_2  1  value  A  4  NULL  NULL   BTREE   
 triggers  1  triggers_2  2  lastchange  A  1826  NULL  NULL   BTREE   
 triggers  1  triggers_3  1  templateid  A  228  NULL  NULL  YES  BTREE   
++++++++++++++
I also see some absurd results in my interface for this query, like vb: 264 or 84 or 56. This is not possible if you look at the were clause. Could it be a hardware problem or the database can't keep up with the selections? How can I diagnose these absurd results?
I use mariadb version 10.1.44 in an Ubuntu version 18.04.4.
Lagrangian Constrained Optimization – Math Stack Exchange
Leave a positive def. sym. (5×5) matrix and r be a vector (size 5).
I'm trying to find a vector x that minimizes x ^ t Ax with the constraints that r ^ t * x> = median (r), x1 + x2 + x3 + x4 + x5<=1 (the elements of x must add up to a values less than or equal to 1), and all elements of x are >= 0.
They told me to use the Lagrangian and the enumeration to find min x, but I'm not sure what the lamda is for each of the 7 constraints.
optimization: how can this line break algorithm consider spaces with a width other than 1.0?
the Algorithm of division and conquest to break lines It is described below, in both Python and Dart (which is similar to Java / C #).
Line breaking is also known as "line wrapping", "word wrapping", or "paragraph formation", and this algorithm is used to achieve minimal irregularity.
This algorithm works, but consider that each space has exactly width = 1.0
.
My question:
How can I modify this algorithm so that it ignores spaces? In other words, have him consider spaces with width 0.0
? (or would it also work for me if I could define the width I wanted for the spaces including 0.0
)
Python implementation:
def divide(text, width):
words = text.split()
count = len(words)
offsets = (0)
for w in words:
offsets.append(offsets(1) + len(w))
minima = (0) + (10 ** 20) * count
breaks = (0) * (count + 1)
def cost(i, j):
w = offsets(j)  offsets(i) + j  i  1
if w > width:
return 10 ** 10
return minima(i) + (width  w) ** 2
def search(i0, j0, i1, j1):
stack = ((i0, j0, i1, j1))
while stack:
i0, j0, i1, j1 = stack.pop()
if j0 < j1:
j = (j0 + j1) // 2
for i in range(i0, i1):
c = cost(i, j)
if c <= minima(j):
minima(j) = c
breaks(j) = i
stack.append((breaks(j), j+1, i1, j1))
stack.append((i0, j0, breaks(j)+1, j))
n = count + 1
i = 0
offset = 0
while True:
r = min(n, 2 ** (i + 1))
edge = 2 ** i + offset
search(0 + offset, edge, edge, r + offset)
x = minima(r  1 + offset)
for j in range(2 ** i, r  1):
y = cost(j + offset, r  1 + offset)
if y <= x:
n = j
i = 0
offset += j
break
else:
if r == n:
break
i = i + 1
lines = ()
j = count
while j > 0:
i = breaks(j)
lines.append(' '.join(words(i:j)))
j = i
lines.reverse()
return lines
Dart implementation:
class MinimumRaggedness {
/// Given some (boxWidths), break it into the smallest possible number
/// of lines such as each line has width not larger than (maxWidth).
/// It also minimizes the difference between width of each line,
/// achieving a "balanced" result.
/// Spacing between boxes is 1.0.
static List> divide(List boxWidths, num maxWidth) {
int count = boxWidths.length;
List offsets = (0);
for (num boxWidth in boxWidths) {
offsets.add(offsets.last + min(boxWidth, maxWidth));
}
List minimum = (0)..addAll(List.filled(count, 9223372036854775807));
List breaks = List.filled(count + 1, 0);
num cost(int i, int j) {
num width = offsets(j)  offsets(i) + j  i  1;
if (width > maxWidth)
return 9223372036854775806;
else
return minimum(i) + pow(maxWidth  width, 2);
}
void search(int i0, int j0, int i1, int j1) {
Queue> stack = Queue()..add((i0, j0, i1, j1));
while (stack.isNotEmpty) {
List info = stack.removeLast();
i0 = info(0);
j0 = info(1);
i1 = info(2);
j1 = info(3);
if (j0 < j1) {
int j = (j0 + j1) ~/ 2;
for (int i = i0; i < i1; i++) {
num c = cost(i, j);
if (c <= minimum(j)) {
minimum(j) = c;
breaks(j) = i;
}
}
stack.add((breaks(j), j + 1, i1, j1));
stack.add((i0, j0, breaks(j) + 1, j));
}
}
}
int n = count + 1;
int i = 0;
int offset = 0;
while (true) {
int r = min(n, pow(2, i + 1));
int edge = pow(2, i) + offset;
search(0 + offset, edge, edge, r + offset);
num x = minimum(r  1 + offset);
bool flag = true;
for (int j = pow(2, i); j < r  1; j++) {
num y = cost(j + offset, r  1 + offset);
if (y <= x) {
n = j;
i = 0;
offset += j;
flag = false;
break;
}
}
if (flag) {
if (r == n) break;
i = i + 1;
}
}
int j = count;
List> indexes = ();
while (j > 0) {
int i = breaks(j);
indexes.add(List.generate(j  i, (index) => index + i));
j = i;
}
return indexes.reversed.toList();
}
}