pseudocode

Algorithm for computing partial orderings of dependency graphs

拈花ヽ惹草 提交于 2019-12-01 14:47:51
问题 I'm trying to compute a partial "topological sort" of a dependency graph, which is actually a DAG (Directed Acyclic Graph) to be precise; so as to execute tasks without conflicting dependencies in parallel. I came up with this simple algorithm because what I found on Google wasn't all that helpful (I keep finding only algorithms that themselves run in parallel to compute a normal topological sort). visit(node) { maxdist = 0; foreach (e : in_edge(node)) { maxdist = max(maxdist, 1 + visit

MIPS Programming: Load Address

元气小坏坏 提交于 2019-12-01 13:54:19
The Background I am a student just beginning to learn MIPS for one of my courses, and my professor is not allowing the usage of pseudo-instructions such as Load Address ( la ) in our code. I am wondering what an example of the correct usage of standard instructions would look like to store the address of a declared variable into a register for use later in the code. My Solution I have currently been attempting to use this code, though I am getting a syntax error in the lui instruction. main: .data Array: .space 80 #Declares that Array will hold 20 integers .text lui $s0, Array #loads most

MIPS Programming: Load Address

南笙酒味 提交于 2019-12-01 11:12:08
问题 The Background I am a student just beginning to learn MIPS for one of my courses, and my professor is not allowing the usage of pseudo-instructions such as Load Address ( la ) in our code. I am wondering what an example of the correct usage of standard instructions would look like to store the address of a declared variable into a register for use later in the code. My Solution I have currently been attempting to use this code, though I am getting a syntax error in the lui instruction. main:

In a triangulated isometric grid, what triangle is a given point in?

时光毁灭记忆、已成空白 提交于 2019-12-01 06:24:36
I have a triangulated isometric grid, like this: (source: mathforum.org ) In my code, triangles are grouped by columns. As I hover the mouse, I want to calculate what triangle the mouse coordinates are in. Is there a simple algorithm to do that? What you want to do is turn this into a grid as much as possible because grids are far easier to work with. The first thing you do is work out what column it's in. You say you store that so it should be easier by doing a simple integer division on the x coordinate by the column width offset by the box start. Easy. After that you want to work out what

Understanding the pseudocode in the Donald B. Johnson's algorithm

江枫思渺然 提交于 2019-12-01 05:49:57
Does anyone know the Donald B. Johnson's algorithm , which enumerates all the elementary circuits (cycles) in a directed graph? I have the paper he had published in 1975, but I cannot understand the pseudocode. My goal is to implement this algorithm in Java. Some questions I have, for example, is what is the matrix A k it refers to. In the pseudocode, it mentions that Ak:=adjacency structure of strong component K with least vertex in subgraph of G induced by {s,s+1,....n}; Does that mean I have to implement another algorithm that finds the A k matrix? Another question is what the following

How to fit a bounding ellipse around a set of 2D points

一世执手 提交于 2019-12-01 04:34:45
Given a set of 2d points (in Cartesian form), I need to find the minimum-area ellipse such that every point in the set lies either on or inside the ellipse. I have found the solution in the form of pseudo-code on this site, but my attempt to implement the solution in C++ has been unsuccessful. The following image illustrates graphically what the solution to my problem looks like: In my attempt, I used the Eigen library for the various operations on matrices. //The tolerance for error in fitting the ellipse double tolerance = 0.2; int n = 10; // number of points int d = 2; // dimension MatrixXd

Understanding the pseudocode in the Donald B. Johnson's algorithm

天涯浪子 提交于 2019-12-01 04:06:56
问题 Does anyone know the Donald B. Johnson's algorithm, which enumerates all the elementary circuits (cycles) in a directed graph? I have the paper he had published in 1975, but I cannot understand the pseudocode. My goal is to implement this algorithm in Java. Some questions I have, for example, is what is the matrix A k it refers to. In the pseudocode, it mentions that Ak:=adjacency structure of strong component K with least vertex in subgraph of G induced by {s,s+1,....n}; Does that mean I

How to fit a bounding ellipse around a set of 2D points

蓝咒 提交于 2019-12-01 03:14:57
问题 Given a set of 2d points (in Cartesian form), I need to find the minimum-area ellipse such that every point in the set lies either on or inside the ellipse. I have found the solution in the form of pseudo-code on this site, but my attempt to implement the solution in C++ has been unsuccessful. The following image illustrates graphically what the solution to my problem looks like: In my attempt, I used the Eigen library for the various operations on matrices. //The tolerance for error in

Algorithm to reach a number in a fixed amount of steps using addition, division and multiplication only

余生长醉 提交于 2019-11-30 13:52:04
问题 Working on a game at work and at one point in the game the player is tossed into a bonus game. The amount they need to win is predetermined, however we'd like to come up with an algorithm which uses addition, multiplication and division to get to that amount in x amount of steps. The amount of steps would be known ahead of time as well, so the algorithm would just need to figure out how to use that amount of steps to reach the number. The only computations you can use are +1 through +15, x2,

What is the meaning of “from distinct vertex chains” in this nearest neighbor algorithm?

自古美人都是妖i 提交于 2019-11-30 13:11:09
问题 The following pseudo-code is from the first chapter of an online preview version of The Algorithm Design Manual (page 7 from this PDF). The example is of a flawed algorithm, but I still really want to understand it: [...] A different idea might be to repeatedly connect the closest pair of endpoints whose connection will not create a problem, such as premature termination of the cycle. Each vertex begins as its own single vertex chain. After merging everything together, we will end up with a