optimization

Good algorithm for a query related problem

纵然是瞬间 提交于 2021-02-11 14:56:21
问题 Given N pairs, we have to find the count of pairs that contain an element k in their range, i.e : If a Pair i is defined as (X i ,Y i ), then if Pair i contain K in its range, then X i <= K <= Y i . Now we are given Q such queries to handle with each query consisting of an integer K. Input: The first line contains two space-separated integers N and Q. Next N lines follow where each line denotes a pair. Each line contains two space-separated integers. Next Q lines follow where each line

Minimizing non-convex function with linear constraint and bound in mystic

99封情书 提交于 2021-02-11 14:19:12
问题 Say I have a non-convex objective function loss that takes a np.ndarray named X whose shape is (n,) and returns a float number. The objective has many many many local minima, since it's essentially a function of np.round(X * c, 2) where c is another constant array of shape (n,). You can imagine something like this: def loss(X: np.ndarray) -> float: c = np.array([0.1, 0.5, -0.8, 7.0, 0.0]) X_rounded = np.round(X * c, 2) return rosen(X_rounded) The linear constraint is expressed with two

DCP requirement violated when specifying constraing in cvxpy, perhaps need to rethink entire formulation of problem

余生颓废 提交于 2021-02-11 14:18:37
问题 This is a follow-up to an earlier specific question, but as I add more complexity to the problem formulation, I realize that I need to take a step back and consider whether cvxpy is the best tool for my problem. What I'm trying to solve: create the largest cluster of a category and company where the average values are above a particular threshold. The trick is that if we include particular categories for a company in the cluster, in order to add another company, that company also should have

Is there a highly performant way to make a 56 bit integer?

删除回忆录丶 提交于 2021-02-11 14:15:10
问题 I am writing a virtual machine that has 8 bit opcodes, and one of the common types for the instructions has the 8-bit opcode, followed in memory by a 56 bit signed integer operand. Originally, I was going to implement this instruction as follows: struct machine_op { std::uint64_t opcode:8 std::int64_t operand:56; }; However, Ive heard no end of comments that using bitfields like this would not be portable, and in particular, it would not guarantee that the operand field would actually be in

How to add indicator constraints in Pulp Python?

本秂侑毒 提交于 2021-02-11 13:46:59
问题 I have a problem that I don't know how to add indicator constraints in pulp . Can anyone help me? For example: I have a decision variable x[(i,j)] , LpBinary and a continuous variable u[i] When x[(i,j)] equals 1 , then u[i] + q[j] == u[j] ( q is just the demand of customers) Thank you for your helping. 回答1: Welcome to SO! My interpretation of your question is that you have binary variables x[(i,j)] , and continuos variables u[i] . When x[(i,j)]==1 then you want to enforce a constraint as

How to add indicator constraints in Pulp Python?

瘦欲@ 提交于 2021-02-11 13:44:34
问题 I have a problem that I don't know how to add indicator constraints in pulp . Can anyone help me? For example: I have a decision variable x[(i,j)] , LpBinary and a continuous variable u[i] When x[(i,j)] equals 1 , then u[i] + q[j] == u[j] ( q is just the demand of customers) Thank you for your helping. 回答1: Welcome to SO! My interpretation of your question is that you have binary variables x[(i,j)] , and continuos variables u[i] . When x[(i,j)]==1 then you want to enforce a constraint as

Time and space complexity of count team question

邮差的信 提交于 2021-02-11 12:44:55
问题 from typing import List def countTeams(num: int, skills: List[int], minAssociates: int, minLevel: int, maxLevel: int) -> int: # WRITE YOUR BRILLIANT CODE HERE qualified = [] possible_teams = [[]] for a in skills: if minLevel <= a <= maxLevel: qualified.append(a) num_teams = 0 while qualified: person = qualified.pop() new_teams = [] for team in possible_teams: print(team) print(person) new_team = [person] + team print(new_team) if len(new_team) >= minAssociates: num_teams += 1 new_teams.append

JAVAFX media : Serious optimization problem

浪子不回头ぞ 提交于 2021-02-11 12:15:51
问题 the program is a system that shows media: images, videos and keeps alternating between them. the problem is the use of increasing memory: after the programming running for 30 minutes, it consumes 1.2gb of ram I do not have much idea of what I can do, I believe that the reason for the increasing memory consumption would be recursion (the function calls itself) or the fact that every time it gives a picture it creates a thread, and when it video it uses the technically 'correct' which is a

Gather AVX2&512 intrinsic for 16-bit integers?

五迷三道 提交于 2021-02-11 12:15:20
问题 Imagine this piece of code: void Function(int16 *src, int *indices, float *dst, int cnt, float mul) { for (int i=0; i<cnt; i++) dst[i] = float(src[indices[i]]) * mul; }; This really asks for gather intrinsics e.g. _mm_i32gather_epi32. I got great success with these when loading floats, but are there any for 16-bit ints? Another problem here is that I need to transition from 16-bits on the input to 32-bits (float) on the output. 回答1: There is indeed no instruction to gather 16bit integers, but

Function tabulation and wrapping

為{幸葍}努か 提交于 2021-02-11 09:12:29
问题 I'm doing [very] intense numerical calculations related to physics using solvers written in C++. A single run can take up to few hours on my PC, and one need dozens. I've found that it is possible to significantly (2-5x) decrease the time almost without losing accuracy, if one tabulates smooth functions and uses tabulated values instead. The code below illustrates what do I mean: main.h #pragma once #include <iostream> #include <chrono> #include <math.h> #include <memory> typedef double(*fnc)