## Trading Auction – Need help with calculating price / quantity of restricted underlying securities for matching

I’m having some difficulty with implementing a non-brute force algorithm for solving the following Problem. If I can get something even close to O(N^3) i’d be happy at this point.

Auction: https://www.investopedia.com/terms/a/auctionmarket.asp

I have an algorithm in place that can do a generic Auction (accumulating bids and offers over a fixed period of time, leading up to an event whereby bids and offers are matched to determine a reference price (the price securities are sold at in the auction)however we’ve just implemented a level of complexity that is throwing me for a loop.

We have a security with underlying shares that contain restrictions on who can own them. During an auction, we need to ensure that buyers can only buy shares they’re allowed based on the underlying restriction.

Example:

Security: Foo -Class A Shares -Class B Shares -Class C Shares

1. John can only buy Class A and Class B (Wants to buy 500 at $1.50) 2. Sally can only buy Class B, and Class C (Wants to buy 300 at$ 1.52)

3. Joel can buy any class. ((Wants to buy 200 @ 1.49)

Sell Orders

1. Xavier owns 500 (200 Class A, 300 class B) and is selling 400 at $1.42 2. Jennifer owns 1000 shares (800 Class B, 200 class C) and is selling 650 at$ 1.50

3. Martha owns 1500 shares (300 Class A, 1200 class C) and is selling 400 at 1.52 The goal is trying to find the price point where the most shares can be sold, while making sure that we’re filling all orders that can be filled. I’ve ran through multiple scenarios on calculating it from a price perspective, and the underlying class perspective, calculating the # of shares that can be sold at each price point, but I’m at a blank as each way I do it, i find I’m missing shares that could be traded. Example: The following illustrates (when we have a correct price) that we also need to match buyer & seller using the most restricted / least tradable security so we match those who can’t trade with much first, then go for those that are less restricted. The above isn’t hard to solve, it’s getting to that point, to figure out the best price and tradeable amount. Any thoughts or ideas on this? Posted on Categories proxies ## An exercise question about maximum matching as I am learning about maximal matching problem, I have this question found in the book, yet left with no answers, and I am not having much thoughts about: Say a matching $$M$$ is a maximal matching of $$G=(V,E)$$ if for every $$e\in E$$\ $$M$$, $$m \bigcup \{ e\}$$ is not a matching; show how to construct a maximal matching in $$O(|E|)$$ time and show that for any maximal matching $$M$$, $$|M|\geq \alpha'(G)/2$$. Thanks in prior! Posted on Categories proxies ## A problem with the greedy approach to finding a maximal matching Suppose I have an undirected graph with four vertices $$a,b,c,d$$ which are connected as in a simple path from $$a$$ to $$d$$, i.e. the edge set $$\{(a,b), (b,c), (c,d)\}$$. Then I have seen the following proposed as a greedy algorithm to find a maximal matching here (page 2, middle of the page) Maximal Matching (G, V, E): M = [] While (no more edges can be added) Select an edge which does not have any vertex in common with edges in M M.append(e) end while return M  It seems that this algorithm is entirely dependent on the order chosen for which edge is chosen first. For instance in my example if you choose edge $$(b,c)$$ first, then the you will have a matching that consists only of $$(b,c)$$. Whereas if you choose $$(a,b)$$ as your starting edge, then the next edge chosen will be $$(c,d)$$ and you have a matching of cardinality 2. Am I missing something, as this seems wrong? I have also seen this described as an algorithm for finding a maximal matching in the context of proving that the vertex cover approximation algorithm selects a vertex cover by choosing edges according to a maximal matching. Any insights appreciated. Posted on Categories proxies ## String matching problem needed some explanation This is a question from CLRS book. (Chapter 32, string matching, the question is the problem for the whole chapter, it’s in the end of the chapter) Let $$y^i$$ denote the concatenation of string y with itself $$i$$ times. For example, $$(ab)^{3}$$ = $$ababab$$. We say that a string $$x\in X$$ has repetition factor $$r$$ if x = $$y^{r}$$ for some string $$y\in X$$ and some $$r > 0$$. Let $$p(x)$$ denote the largest $$r$$ such that $$x$$ has repetition factor $$r$$. Give an efficient algorithm that takes as input a pattern $$P[1..m]$$ and computes the value $$p(P_i)$$ for $$i = 1, 2,\dots,m$$. What is the running time of your algorithm? I found an answer like this: First compute Prefix function (based on the prefix function from the book), so we return $$π$$. Then, Suppose that $$π[i] = i −k$$. If $$k|i$$, we know that $$k$$ is the length of the primitive root, so, the word has a repetition factor of $$\frac{i}{k}$$. We also know that there is no smaller repetition factor $$i$$. Now, suppose that we have $$k$$ not dividing $$i$$. We will show that we can only have the trivial repetition factor of 1. Suppose we had some repetition $$y^{r} = \Pi$$. Then, we know that $$π[i] ≥ y^{r}−1$$. However, if we have it strictly greater than this, this means that we can write the $$y$$’s themselves as powers because we have them aligning with themselves. COMPUTE-PREFIX-FUNCTION (P) 1 m = P.length 2 let π be a new array 3 π= 0 4 k = 0 5 for q = 2 to m 6 while k > 0 and P[k+1] != P[q] 7 k = π[q] 8 if P[k+1] != P[q] 9 k = k + 1 10 π[q] = k 11 return π  The prefix function is a part of KMP algorithm KMP-MATCHER (T,P) 1 n= T.length 2 m =P.length 3 π=COMPUTE-PREFIX-FUNCTION (P) 4 q= 0 // number of characters matched 5 for i = 1 to n // scan the text from left to right 6 while q > 0 and P[q+1] != T[i] 7 q= π[q] // next character does not match 8 if P[q+1] == T[i+1] 9 q = q + 1 // next character matches 10 if q == m // is all of P matched? 11 print “Pattern occurs with shift” i - m 12 q=π[q] // look for the next match  I can’t still really understand completely the answer. Why should we suppose $$k$$ not dividing $$i$$? And the explanation for the case of $$k$$ not dividing $$i$$, the repetition factor is 1, is confusing to me. Posted on Categories proxies ## String matching problem needed some explanation This is a question from CLRS book. (Chapter 32, string matching, the question is the problem for the whole chapter, it’s in the end of the chapter) Let $$y^i$$ denote the concatenation of string y with itself $$i$$ times. For example, $$(ab)^{3}$$ = $$ababab$$. We say that a string $$x\in X$$ has repetition factor $$r$$ if x = $$y^{r}$$ for some string $$y\in X$$ and some $$r > 0$$. Let $$p(x)$$ denote the largest $$r$$ such that $$x$$ has repetition factor $$r$$. Give an efficient algorithm that takes as input a pattern $$P[1..m]$$ and computes the value $$p(P_i)$$ for $$i = 1, 2,\dots,m$$. What is the running time of your algorithm? I found an answer like this: First compute Prefix function (based on the prefix function from the book), so we return $$π$$. Then, Suppose that $$π[i] = i −k$$. If $$k|i$$, we know that $$k$$ is the length of the primitive root, so, the word has a repetition factor of $$\frac{i}{k}$$. We also know that there is no smaller repetition factor $$i$$. Now, suppose that we have $$k$$ not dividing $$i$$. We will show that we can only have the trivial repetition factor of 1. Suppose we had some repetition $$y^{r} = \Pi$$. Then, we know that $$π[i] ≥ y^{r}−1$$. However, if we have it strictly greater than this, this means that we can write the $$y$$’s themselves as powers because we have them aligning with themselves. COMPUTE-PREFIX-FUNCTION (P) 1 m = P.length 2 let π be a new array 3 π= 0 4 k = 0 5 for q = 2 to m 6 while k > 0 and P[k+1] != P[q] 7 k = π[q] 8 if P[k+1] != P[q] 9 k = k + 1 10 π[q] = k 11 return π  The prefix function is a part of KMP algorithm KMP-MATCHER (T,P) 1 n= T.length 2 m =P.length 3 π=COMPUTE-PREFIX-FUNCTION (P) 4 q= 0 // number of characters matched 5 for i = 1 to n // scan the text from left to right 6 while q > 0 and P[q+1] != T[i] 7 q= π[q] // next character does not match 8 if P[q+1] == T[i+1] 9 q = q + 1 // next character matches 10 if q == m // is all of P matched? 11 print “Pattern occurs with shift” i - m 12 q=π[q] // look for the next match  I can’t still really understand completely the answer. Why should we suppose $$k$$ not dividing $$i$$? And the explanation for the case of $$k$$ not dividing $$i$$, the repetition factor is 1, is confusing to me. Posted on Categories proxies ## How does the asterisk (*) work in the wildcard matching problem? This is a wildcard matching problem. Given a pattern P containing letters and character * that can match an arbitrary string of characters (including an empty string), my task is to write a polynomial-time algorithm to determine whether such a pattern P occurs in a given text T. So here is my answer for the problem. We can use dynamic programming to solve this problem. Let us have a 2D boolean array dp[i][j]. dp[i][j] returns true if there is a match between the pattern and the string. Initialize dp[i][j] = false -dp = true since an empty string matches an empty pattern. -dp[j] = dp[j-1] (= true) if P[j] = * for 1<= j <=m since an empty string matches ‘*’ as long as previous characters match. In other words, once P[j-1] != “*”, dp[j] will be false afterwards. -If P[j] = ‘*’, we have dp[i][j] = dp[i-1][j] || dp[i][j-1] For dp[i-1][j], ‘*’ acts as an empty string. E.g. ab and ab* For dp[i]p[j-1], ‘*’ acts as any sequences. E.g. abcd and ab* In other words, if P[j] = ‘*’ and (dp[i-1][j] || dp[i][j-1]) = true, dp[i][j] = true -If P[j] = T[i], it boils down to match T(i-1) and P(j-1). dp[i][j] = dp[i-1][j-1] For other cases, dp[i][j] is false. Pseudocode: tLen = T.length pLen = P.length Initialize dp[tLen+1][pLen+1] = false Dp = true For j = 1 to pLen If P[j] = ‘*’ dp[i][j] = dp[j-1] for i =1 to tLen for j=1 to pLen if P[j] = ‘*’ dp[i][j] = dp[i][j-1] or dp[i-1][j] else if P[j] = T[i] dp[i][j] = dp[i-1][j-1] else dp[i][j] = false Return dp[tLen][pLen] The algorithm fills a tLen x pLen table, so the running time is O(nm)  During a discussion in class, my professor said my answer is vague. He asked me if I had considered * can appear in the middle of the pattern and it can appear several times in the pattern. In particular, consider pattern abcccdeeef and string abcdcccccdefefeefeeef How does this algorithm determine, which c in the pattern should match with which c in the text? How does it with e? My understanding towards this problem is that what matters is the final result of dp[tLen][pLen] and we use a table to compare substrings with each other.The character * would probably match any character it encounters. We just derive our answers from previous steps to fill out the whole table so that we can get the final result of dp[tLen][pLen]. However, for his specific question, I can’t think of a reasonable way to answer. Any help with the explanation would be appreciated. Posted on Categories proxies ## Explain this Graph Matching solved in Linear Time I’m interested in a better explanation about the paper Computing Optimal Assignments in Linear Time for Approximate Graph Matching. The graph edit distance is approximated by assignments in linear time. Briefly speaking there is an embedding of optimal assignment costs into a Manhattan metric: $$φ_c(A) = [A_{uv}^← · w(uv)]_{uv∈E(T)}$$. The Manhattan distance between these vectors is equal to the optimal assignment costs between the sets. The problem is: it is not throughly explained how I find $$A_{uv}^←$$ and how I use Weisfeiler-Lehman to label the vertices of a tree in the following figure: Please, explain how I find $$A_{uv}^←$$ and how I label that tree. ## Attach PDF to flow from SharePoint list matching employee number I’ve been tasked with creating a flow that will send an email to all our staff with custom attachments. A typical attachment would be in this format: “John.Smith-123456789.PDF” (FirstName.LastName-EmployeeNumber) As we have approximately 1500 staff there are cases where we have duplicate names so simply cannot extract the name from the file and match it to a username. I had a theory that if we have a list of All names, email addresses and employee numbers we could then match the employee number in the filename against the one in the list and send an email to the email address associated with the employee number attaching the PDF file. What is the best way of doing this as I dont yet have the PDF files. This is how my current flow looks. Posted on Categories buying proxies ## REST API: No route was found matching the URL and request method I’m having issues adding a custom REST API route to WordPress. Using my own plugin, i’ve registered the route as followed: add_action( 'rest_api_init', function() { register_rest_route(  namespace, 'handler_mijnenergie', array(     'methods'   => '\WP_REST_Server::CREATABLE ',     'callback'  => [ \$  this, 'handle_energie_data' ]   ), false ); } ); 

When calling the namespace “/wp-json/watz/v1” I get a correct response in Postman that the route is shown. However, when i try to access the route request directly, i get thrown a 404 error. So far I’ve tried: