mathematical optimization – Problem with NMinimize – continuous and discrete variables

Dear Mathematica experts,
I have a problem with the optimization of the objective Z depending on continuous and discrete variables. The error that occurs constantly is “The following constraints are not valid: ….. Constraints should be equalities, inequalities, or domain specifications involving the variables.” I read a lot about this problem here, but as far as I understand each of the cases is individual. If the constraints are incompatible, shouldn’t a message be displayed that they are not being satisfied? As far as I understand the mentioned error message, the restrictions have not been entered correctly. Would you help me clarify the problem? Thank you in advance.

PS: In vars list b and r are Integers.

Mmin = 102500; Mmax = 193000; th2max = 430*Pi/180; th2min = 310*Pi/180;

d(b_) := Which(b == 1, 0.04, b == 2, 0.05, b == 3, 0.063, b == 4, 
   0.08, b == 5, 0.1, b == 6, 0.125, b == 7, 0.14, b == 8, 0.16, 
   b == 9, 0.18, b == 10, 0.2, b == 11, 0.22, b == 12, 0.25, b == 13, 
   0.28, b == 14, 0.32);

h(r_) := Which(r == 1, 0.15, r == 2, 0.30, r == 3, 0.45, r == 4, 0.60,
    r == 5, 0.75, r == 6, 0.9, r == 7, 1.05, r == 8, 1.30, r == 9, 
   1.45, r == 10, 1.6, r == 11, 1.75, r == 12, 1.9, r == 13, 2.05, 
   r == 14, 2.2);

Lt(b_) := 0.291669 + 4.1388707*d(b);

F(b_, p_) := 2*p*Pi*d(b)^2/4; 

S1max(LL1_?NumericQ, LL2_?NumericQ, LL3_?NumericQ, 
   ddelta1_?NumericQ) :=Module({L1 = LL1, L2 = LL2, L3 = LL3, delta1 = ddelta1, S1max},
   S1max = Sqrt(Abs(L1^2+L2^2+L3^2+2*L1*(L2*Sin(th2max + delta1)-L3*Cos(th2max + delta1)))));

kmax(LL1_?NumericQ, LL2_?NumericQ, LL3_?NumericQ, ddelta1_?NumericQ) :=
  Module({L1 = LL1, L2 = LL2, L3 = LL3, delta1 = ddelta1, Amax, Bmax, 
    ps1max, kmax},
   Amax = (L1*Cos(delta1 + th2max) - L3)/S1max(L1, L2, L3, delta1);
   Bmax = (L1*Sin(delta1 + th2max) + L2)/S1max(L1, L2, L3, delta1);
   ps1max = ArcTan(Amax, Bmax);
   kmax = -L1*Sin(delta1 + th2max - ps1max));

S1min(LL1_?NumericQ, LL2_?NumericQ, LL3_?NumericQ, 
   ddelta1_?NumericQ) :=Module({L1 = LL1, L2 = LL2, L3 = LL3, delta1 = ddelta1, S1min},
   S1min =Sqrt(Abs(L1^2+L2^2+L3^2+2*L1*(L2*Sin(th2min+delta1)-L3*Cos(th2min+delta1)))));

kmin(LL1_?NumericQ, LL2_?NumericQ, LL3_?NumericQ, ddelta1_?NumericQ) :=
  Module({L1 = LL1, L2 = LL2, L3 = LL3, delta1 = ddelta1, Amin, Bmin, 
    ps1min, kmin},
   Amin = (L1*Cos(delta1 + th2min) - L3)/S1min(L1, L2, L3, delta1);
   Bmin = (L1*Sin(delta1 + th2min) + L2)/S1min(L1, L2, L3, delta1);
   ps1min = ArcTan(Amin, Bmin);
   kmin = -L1*Sin(delta1 + th2min - ps1min));

maxM(LL1_?NumericQ, LL2_?NumericQ, LL3_?NumericQ, ddelta1_?NumericQ,pp_?NumericQ, bb_?NumericQ) := Module({L1 = LL1, L2 = LL2, L3 = LL3, delta1 = ddelta1, p = pp,b = bb, maxM},
   maxM = F(b, p)*kmax(L1, L2, L3, delta1) - Mmax);

minM(LL1_?NumericQ, LL2_?NumericQ, LL3_?NumericQ, ddelta1_?NumericQ, 
   pp_?NumericQ, bb_?NumericQ) :=Module({L1=LL1, L2=LL2, L3=LL3, delta1=ddelta1, p=pp, b = bb, minM},
   minM = F(b, p)*kmin(L1, L2, L3, delta1) - Mmin);

Z(LL1_?NumericQ, LL2_?NumericQ, LL3_?NumericQ, ddelta1_?NumericQ,pp_?NumericQ, bb_?NumericQ, rr_?NumericQ,) := 
  Module({b=bb, r=rr, L1=LL1, L2=LL2, L3=LL3, p=pp, delta1=ddelta1, f1, f2, k1, k2, Z},
   f1 = 2*h(r)*Pi*(d(b)^2)/4 ;
   f2 = (maxM(L1,L2,L3,delta1,p,b)-Mmax)^2+(minM(L1,L2,L3,delta1,p,b)-Mmin)^2;
   k1 = 0.5; k2 = 1 - k1;
   Z = k1*f1 + k2*f2

cons = {
   b >= 1, b <= 14,
   r >= 1, r <= 14,
   L1 >= 3, L1 <= 4.1,
   L2 >= 0.2, L2 <= 1.5,
   L3 >= 0.2, L3 <= 1.5,
   delta1 >= 14*Pi/180, delta1 <= 21*Pi/180,
   p >= 6*10^6, p <= 30*10^6,

vars = {L1,L2,L3,delta1,p,b(Element)Integers,r(Element)Integers};

opt = NMinimize({Z(L1,L2,L3,delta1,p,b,r),cons},vars,MaxIterations->500)

Question about deadly diamond problem (multiple inheritance)

I know in stackoverflow it has many people asked deadly diamond problem already, but the question that they asked is not what I want to ask, so could anyone please tell me what is the solution when I encounter this kind of problem.

The following picture (A) is a typical diamond problem , and (B) is the solution that change musician and actor from class to interface for achieving multiple inheritance. But what I want to ask is, how about if I also need musician and actor class? In general not all people are both musician and actor, some are only musician and some are only actor, if I change these 2 classes to interfaces, is that means if I need musician, I use Performer class to create object also? If so, why should I create Musician and Actor interface? Even consider future inheritance problem, as shown in (C), I don’t think interface can help any code reusable, the only thing can help is about restrict person it must obey what musician interface have. I really get confuse of these 2 questions, can anyone please tell me in detail? Thank you very much for your help.

diamond problem image shown

web application – watch out for directory traversal/path traversal security problem

After some research on the internet and read some articles/posts about directory traversal/path traversal security problem, I still don’t quite get when I need to watch out for this kind of security problem, should I always need to watch out for this kind of security problem when I am developing a back-end or only when I am doing/implementing certain things/features?

Problem with creating an instance of a class in SPFX(TypeScript/React)

I am facing a problem with creating an instance of a class in SPFX. I am not sure what I should put in as a parameter. The compiler complains on whatever I put as a parameter. Here is my code:

import { DefaultButton, values } from 'office-ui-fabric-react';
import * as React from 'react';
import { IReduxCounterProps } from '../components/IReduxCounterProps';
import Output from '../components/CounterOutput/Output';
import { ICounterState } from './ICounterState';

export default class Counter extends React.Component<IReduxCounterProps, ICounterState> {

    constructor(props: IReduxCounterProps) {
        this.state = {
            counter: 0

    private counterOnIncrement() {
        console.log("Counter Increment");
        this.setState({ counter: this.state.counter + 1 });

    private counterOnDecrement() {
        console.log("Counter Decrement");
        this.setState({ counter: this.state.counter - 1 });
    public render() : React.ReactElement<IReduxCounterProps> {
                <Output value={this.state.counter} description="test" />
                <DefaultButton text="Increment" onClick={() => this.counterOnIncrement()} />
                <DefaultButton text="Decrement" onClick={() => this.counterOnDecrement()} />

const states = new Counter(1);
const test = new Counter("blavla");
const props = new Counter(props).state.counter;


export interface IReduxCounterProps {
  description: string;
  value: number;


export interface ICounterState {
    counter: number;

I am actually practicing some Redux on SPFx so what I am trying to do is access my state outside the Counter class in order to pass my state as a prop but the instance is requiring a parameter and complains on whatever I put as a parameter.

Here are my errors:

enter image description here

I would appreciate if someone could help me out with this issue.
Thanks in advance.

differential equations – How to solve this problem similar to eigenvalue problem but with sources?

I have two coupled differential equations with this structure:

where all the functions $f_i(r),g_i(r),V_i(r)$ and $S_j(r)$ are known (and non linear). I have to solve for the parameter $omega$ and for the functions $h_{00}(r)$, $h_{22}(r)$. The boundary conditions are that the functions are bounded in the origin and fall off as $r^{-n}$ at infinity.

Without the sources, this is an eigenvalue problem, but I have sources: how do I treat this kind of problem?

For definiteness consider a system of the form:

r^-2 D(h00(r),{r,2}) + r^-3 D(h00(r),r) + r D(h22(r),r) + (w^2 + r^-2)h00(r) + (w^2 + 2 r^-2)h22(r) == Exp(-r)
D(h22(r),{r,2}) + r^-1 D(h22(r),r) + D(h00(r),r) + (w^2 + r^-3) h22 ==  r^2 Exp(-r)

EDIT I have been experimenting with NDEingenvalues and similar functions: they seem to ignore the source term, I mean the eigenvalues do not change with the source: do I miss something?

linear algebra – Estimating Zeta from Hv and Hu , system of equations, estimation problem

Does anyone here know how $beta$ could be estimated in terms of $H_u, H_v $ in the below equations,

$$ H_u = left | zeta; left(frac{ e^{-jcdot 2cdotpi}-e^{-jcdot 2cdotpi(1/T)(T-Delta t)}}{j2pi}right)-zeta-beta right|^2 $$

$$ H_v = left | zeta; left(frac{ e^{jcdot 2cdotpi}-e^{jcdot 2cdotpi(1/T)(Delta t)}}{j2pi}right)+zetabeta right|^2 $$

This is absolute sqauare of $H_v$ and $H_u$

I am working on an estimation problem where from $H_u , H_v $ they estimated $beta$ that is inside $H_u$ and $H_v$.

Anyone who could tell me about any mathematical procedure that how I can we do so?

A previous example where we did so… Almost same problem

$$ A_1 = left | alpha; left(frac{ 1- e^{-jcdot 2cdotpi rho}}{j2pi rho}right) right|^2 $$

$$ A_2 = left |alpha; left(frac{ 1- e^{-jcdot 2cdotpi rho}}{j2pi+j2pi rho}right) right|^2 $$
$$ rho=frac{A_2+sqrt(A_1A_2)}{A_1-A_2} $$

divided $A_1$ by $A_2$ equations


which is a quadratic in ρ.

I Solved it and select the root you I needed. I found $rho $ in terms of $A_1, A_2 $

google assistant – Problem creating a reminder with date/time in title

Using Android 9 on a Pixel 2, I can recreate this problem reliably.

Let’s say currently it is January 20. I prompt Google Assistant to start making a reminder for a certain date and time, such as:

“Remind me on February 8th at 6 pm”,

to which it replies:

“Okay, what’s the reminder?”

If I then want to the reminder text to say something like:
“Appointment tomorrow at noon”,
Google will interpret that as a new reminder set for January 21 at noon, instead of a reminder on February 8th at 6 pm saying “Appointment tomorrow at noon”.

This seems like a mistake, especially since Google specifically saved the date and time of the original request and prompted me just for the reminder text.

Has anyone found a solution to this? Many thanks.

algorithms – Optimization problem over bidirectional connected graph

A company has several automatic vertical warehouses (called elevators). Each elevator have several trays and each tray has several slots. A slot contains a given quantity of a given article. Elevators, trays and slots are identified by unique IDs and slot also have access to the ID of their own article. In the same tray there can be multiple slots with the same article.

I have to design an algorithm which, given an order list (we can model it as a dictionary with articles’ IDs as key and quantity needed as values), returns the minimum list of trays needed to satisfy the order.

This is quite different from a standard warehouse optimization problem because we are not considering the physical distances between each tray, since the elevators are automatic and they give us the tray, while in the classical problem is the human who moves toward the tray to pick the item from it.

A distance function is given: d(a, b) which returns 1 if tray a and b are on different elevators and returns 2 if they’re on the same one. That could be counter-intuitive, but remember that these are vertical elevators, so the time needed to change tray on the same elevator is greater than the time to move to a different elevator with the tray already in bay. Furthermore, if we use more elevators at the same time, we can “parallelize” the picking process (man A pick from elevator 1 while man B picks from elevator 2…) Anyway, this function is given and I cannot change it.

After reading through articles about warehouse optimization, I’ve decided to take an heuristic approach.
I’ve modeled a sort of euclidean space, with an axes for each article contained in the order. Then we can consider a tray as a point on that space, with coordinates for each axes equal to the quantity that tray has of the article corresponding to that axes. In the same way we can imagine our order as a point.
Then I’ve create a heuristic function, f(order o, tray t), which returns the “euclidean distance” from point-tray t to the point-order o. The idea is that the more a tray is “near” the order, the more article we can pick out of it.

So, to satisfy the order, I simply compute f(order o, tray t) for each tray in every elevator. Then I order it by descending value and finally I greedily take a tray with the minimum distance from the order. This will be repeated until we collect enough articles to satisfy the order.

Now I `d like to find a better solution, taking into account also the physical distances from tray returned by function d.

I`ve tried to build a graph in which each node is a tray and is connected to each of the others by a directed edge. The weights of the edge from node i to node j will be equal to the physical distance from tray i to tray j, plus the heuristic function computed on tray j

--> w(i, j) = d(i, j) + f(order, j)

This results in a fully-connected, bidirectional graph (each node linked with each other node by both an incoming and an outgoing edge).
I want to apply some algorithm of shortest path (or any other useful algorithm) taken from graph theory on this graph but I couldnt find anything really helpful. Ive tried to apply the A* search algorithm (using function d as gScore and my function f as heuristic) but it gives me no result. I think A* can`t be applied in such a graph (bidirectional and fully connected).

Is there any algorithm I can apply on such a graph? Or maybe the graph is not the right structure to represent my problem. I`m open to new solutions.

WordPress Ajax load more problem, how to send wp_query to ajax PHP file

I have a load more script in WordPress, everything is perfect on the homepage but there is a problem in the taxonomy page. So when you click on the category page, it pulls out all the articles. When you manually enter the category name in $args__load('category_name') below, everything is fine. But when you call the category of the current page with $wp_query, it extracts all articles. Thank you in advance for the help.


wp_enqueue_script('my__load__more', get_template_directory_uri() . '/assets/js/load_more.js', array('jquery'), '1.0.0', true);
wp_localize_script('my__load__more', 'ajaxurl', admin_url('admin-ajax.php'));
function my__load__more() {
    $count = get_option('posts_per_page');
    $add = $_POST('addNum');
    $getChoose = $_POST('getChoose');
    $count = $count + $add;
    $read = 1;

    $args__load = array(
    'posts_per_page' => -1,
    'post_type'      => 'post',
    'post_status'    => 'publish',

    global $wp_query;

    $vardi = $wp_query->query_vars;

    $args__load('category_name') = $vardi('category_name');

    $articles = new WP_Query( $args__load );
    $getPosts = array();
    if( $articles->have_posts() ) {
    while( $articles->have_posts() ) {
    if($read > $count && $read <= $count+$getChoose) {
    ob_start(); // start the buffer to capture the output of the template
    $getPosts() = ob_get_contents(); // pass the output to variable
    ob_end_clean(); // clear the buffer
    if( $read == $articles->found_posts )
    $getPosts() = false;
echo json_encode($getPosts);
add_action( 'wp_ajax_my__load__more', 'my__load__more' );
add_action( 'wp_ajax_nopriv_my__load__more', 'my__load__more' );


    "use strict";

    var addNum     = 0;
    var getChoose  = 5;
    var clicked    = false;
    var readyCount = false;

    $(".load__more__button").click(function() {
        if (!clicked) {
            if (readyCount == true) {
                addNum = addNum + getChoose;
            readyCount = true;
                'action': 'my__load__more',
                'addNum': addNum,
                'getChoose': getChoose,
            function(response) {
                var posts = JSON.parse(response);
                for( var i = 0; i < posts.length; i++ ) {
                    if( posts(i) == false )
                    $('.load__more__button').text('Load More');
            $(document).ajaxStop(function () {
                clicked = false;
            clicked = true;


But replacing this part with an existing category name, it works.

    global $wp_query;

    $vardi = $wp_query->query_vars;

    $args__load('category_name') = "business" /*$vardi('category_name');*/

I guess it doesn’t see wp_query.