optimization

How to apply inequality constraints in Mystic

痴心易碎 提交于 2020-01-25 07:23:09
问题 I'm trying to maximise an objective subject to an inequality constraint using Mystic but am struggling to see how to apply the penalty constraints. The problem is non-convex and involves maximising the objective where there is only one variable that will be changing (x). I'm trying Mystic because I've heard that it is good for large scale optimisation, and x is a 1D array contain millions of items (size N). There are three 1-D arrays of numbers a, b, and c all with N number of values, (the

Shifting bytes and remaining values casted to int (interested in two's complement)

徘徊边缘 提交于 2020-01-25 07:15:09
问题 Why does the code that you see below give these results? void loop() { byte test = 00000101; Serial.print("The byte test is: "); Serial.println(test); int x = (int)test; int y = (int)test<<8; Serial.print("The int x is: "); Serial.println(x); Serial.print("The int shifted y is: "); Serial.println(y); byte tost = 10000001; int z = test + tost; Serial.print("The int z is: "); Serial.println(z); delay(1000); } Results : The byte test is: 65 The int x is: 65 The int shifted y is: 16640 The int z

how to test for bipartite in directed graph

谁都会走 提交于 2020-01-25 03:39:05
问题 Although we can check a if a graph is bipartite using BFS and DFS (2 coloring ) on any given undirected graph, Same implementation may not work for the directed graph. So for testing same on directed graph , Am building a new undirected graph G2 using my source graph G1, such that for every edge E[u -> v] am adding an edge [u,v] in G2. So by applying a 2 coloring BFS I can now find if G2 is bipartite or not. and same applies for the G1 since these two are structurally same. But this method is

How to get the count of each value from different fields using Django Queries?

谁说我不能喝 提交于 2020-01-24 21:54:08
问题 I have a Django model with many fields. Let's say the model is like this: class Foo(models.Model): name = models.CharField(max_length=50) type = models.CharField(max_length=100, blank=True) foo_value = models.CharField(max_length=14, blank=True) # ... and many many other fields Now I need to run a query to get me all the data from all fields. This would be Foo.objects.all() , right? Now I need for each name (which means I will group by name) to do some things. First, the problem is if I want

Optimise two SQL queries and a list comprehension

我的未来我决定 提交于 2020-01-24 21:06:46
问题 I have those two models (simplified): class Place(OrderedModel): name = models.CharField(max_length=100) class Team(models.Model): name = models.CharField(max_length=100) places = models.ManyToManyField(Place, blank=True) Say that there are ten instances of Place . But only five instances of Team . I want to return a list of booleans in the order of entries in Place , where True means that Team.places contains that place and False (obviously) means that it doesn't. The Team.places field has

Shortest path through ordered circular waypoints

元气小坏坏 提交于 2020-01-24 20:29:05
问题 I am trying to implement an algorithm which computes the shortest path and and its associated distance from a current position to a goal through an ordered list of waypoints in a 2d plane. A waypoint is defined by its center coordinates (x, y) and its radius r. The shortest path have to intersect each waypoint circumference at least once . This is different from other path optimization problems because I already know the order in which the waypoints have to be crossed. In the simple case,

Optimize sum of powers with constant double exponent

本秂侑毒 提交于 2020-01-24 18:06:32
问题 I have implemented an algorithm which at some point needs to calculate the sum of the powers of the elements of a vector. The power is a positive double which is constant during the loop. I figured out, that this calculation is currently the bottleneck of my program and wonder if there is a way to speed up the following code snippet: double SumOfPowers(std::vector<double>& aVector,double exponent) { double help = 0; size_t sizeOfaVector = aVector.size(); for (size_t k = 0; k < sizeOfaVector;

Better way to handle n number of if-else if in java

天大地大妈咪最大 提交于 2020-01-24 15:42:06
问题 I was wondering if there is any better way to handle n no. of if/else-if block in Java. I have a situation where I need to print different values based on n no. of if/else-if/conditions blocks like if(p==1 && q==r) System.out.println("Condition 1"); else if(r==p && q==9) System.out.println("Condition 2"); else if(z==1 && s==r) System.out.println("Condition 3"); else if(p==1 || x==r && y==7) System.out.println("Condition 4"); else if(q==z && y==r || p==4) System.out.println("Condition 5");

Rows_sent: 12 Rows_examined: 549024 - how to optimize mySQL query?

倖福魔咒の 提交于 2020-01-24 15:41:25
问题 I have a database with listings on quite a good server (Quad Core Xeon 2.0Ghz, 16GB RAM, SSD Drives). The database has about 180,000 listings. There's no traffic yet on the server and I'm just testing it with a lot of listings to ensure there are no problems later on when there's actually that many live listings and actual traffic. But even with no traffic yet, I feel like they should return faster than they actually are. From the slow queries log, I was able to find this: # Query_time: 1

Optimizing code for more clearness and efficiency

£可爱£侵袭症+ 提交于 2020-01-24 15:16:58
问题 This code works fine, but I need to simplify it for more clearness and hopefully more efficiency: int i = 0; if (p.cap()) n++; if (p.creditcard()) n++; if (p.email()) n++; [...] if (p.price()) n++; if (p.url()) n++; if (p.zip()) n++; if (n == 0) p.standard(); As the code says, I need to call multiple methods (I don't know the finite number of them). Every p. ()* method returns a boolean value, and n is incremented only if the value returned is true. If n==0 (this happens when EVERY method