Train track assembly algorithm [closed] - algorithm

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I recently bought a toy train for my kid. And when assembling it I wondered if I could create an app where you put in what peaces and how much of them you have and the result is track diagram, with at leased one closed circuit. So, my input will be how much peaces I have from each type, this is the types:
And the output will be something like this:
What algorithm can I use for implementing this, and if you have any suggestion or pointers please tell me.

You could use a brute force approach where you start with piece one and then try all the remaining pieces for piece two and then all the remaining ones for piece three and so on. You'd build up lots of layouts in parallel, for example
Piece1-Piece2-Piece3-...
Piece1-Piece3-Piece4-...
Piece1-Piece4-Piece5-...
...
(Where - indicates a join).
When you get to a point that the layout becomes invalid you could stop and cross it off your list.
An advantage of this approach is that it will find a solution if there is one. A disadvantage is that it could take a long time.
If you're after a single layout the question is how to determine which is "best". One way to do this might be to assign different weightings to different pieces and then you could assess your layout using these scores.
You could optimize this by categorizing your pieces, for example into straight ones and curved ones, and then making some deductions based on how many of each you have. For example, if you have 4 curved pieces and 16 straight pieces you could conclude that you've got 4 corners and the others must be the sides. So from this starting point you would come up with several layouts in parallel and when you get to a point that the layout becomes invalid you could stop and cross it off your list.
Another optimization might be to create a list of sample layouts and build on those. For example, if you had a sample loop layout as a starting point you could try replacing one of your straight pieces with a set of points and then building from there.

Related

Which navigation methods would be the most performant and flexible for a game with a very large number of AI on a dynamic playfield? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I'm not 100% sure what factors are important when deciding whether to use Unity's NavMesh vs an advanced pathing algorithm such as HPA* or similar. When considering the mechanics below, what are the implications of using Unity's NavMesh vs rolling my own algorithms:
Grid based real-time building.
Large number of AI, friendly, hostile, neutral. Into the hundreds. Not all visible on screen at once but the playfield would be very large.
AI adheres to a hierarchy. Basically does things where AI entities issues commands, receive commands, and execute them in tandem with one-another. This could allow for advanced pathing to be done on a single unit that relays rough directions to others where they can commence lower-level pathing to save on performance.
World has a strong chance of being procedural. I wanted to go infinite proc-gen but I think that's out of scope. I don't intend on having the ground plane being very diverse in regards to actual height, just the objects placed on it.
Additions and removals within the environment will be dynamic at run-time by both the player and AI entities.
I've read some posts talking about how NavMesh can't handle runtime changes very well but have seen tutorials/store assets that are contrary to that. Maybe I could combine methods too? The pathing is going to be a heavy investment of time so any advice here would be greatly appreciated.
There are lots of solutions. It's way too much for a single answer, but here's some keywords to look into:
Swarm pathfinding
Potential fields
Flocking algorithms
Boids
Collision avoidance
Which one you use depends on how many units will be pathing at a time, whether they're pathing to the same place or different places, and how you want them to behave if multiple are going to the same place (eg. should they intentionally avoid collisions with each other? Take alternate routes when one is gridlocked? Or all just stupidly cram into the same hallway?)

How to create random incongruous shapes that don't overlap each others in P5.js [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I'm looking to create shapes like this :
https://www.lucegallard.com/?lightbox=dataItem-isiz1h39
But they have to be generated at random and never overlap. It would be too easy to just use beginShape() and curveVErtex(x,y), etc.
Plus the result would we static, it needs to be changed easily and randomly. My question is "is there a function to create 'weird' ellipses?" or "Could anyone help me with an algorithm to achieve this?"
Thanks allot in advance!
Stack Overflow isn't really designed for general "how do I do this" type questions. It's for specific "I tried X, expected Y, but got Z instead" type questions. But I'll try to help in a general sense:
You need to break your problem down into smaller pieces and take those pieces on one at a time. Try to create a program that just generates a single random shape. Then try to add a second randomly-generated shape that doesn't intersect with the first shape.
Think about how you would describe this program to somebody who can't see the website you've linked in your post. Try to describe it in as much detail as you can. Pretend you have a friend who has never seen what you're talking about. Can you write down a set of steps that this friend could follow to draw what you're talking about? When you have those steps written down, that's an algorithm that you can start thinking about implementing with code.
A simple check would be for each new point you generate, check whether it's inside any previous shapes. If so, go back and pick a different new point. That will at least get you started going in a direction.
If you get stuck, please post a MCVE along with a more specific technical question. Good luck.

How does SVM work? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Is it possible to provide a high-level, but specific explanation of how SVM algorithms work?
By high-level I mean it does not need to dig into the specifics of all the different types of SVM, parameters, none of that. By specific I mean an answer that explains the algebra, versus solely a geometric interpretation.
I understand it will find a decision boundary that separates the data points from your training set into two pre-labeled categories. I also understand it will seek to do so by finding the widest possible gap between the categories and drawing the separation boundary through it. What I would like to know is how it makes that determination. I am not looking for code, rather an explanation of the calculations performed and the logic.
I know it has something to do with orthogonality, but the specific steps are very "fuzzy" everywhere I could find an explanation.
Here's a video that covers one seminal algorithm quite nicely. The big revelations for me are (1) optimize the square of the critical metric, giving us a value that's always positive, so that minimizing the square (still easily differentiable) gives us the optimum; (2) Using a simple, but not-quite-obvious "kernel trick" to make the vector classifications compute easily.
Watch carefully at how unwanted terms disappear, leaving N+1 vectors to define the gap space in N dimensions.
I'll give you a very small details that will help you to continue understanding how SVM works.
make everything simple, 2 dimensions and linearly seperable data. The general idea in SVM is to find a hyperplan that maximize the margine between two classes. each of your data is a vector from the center. One you suggest a hyperplan, you project you data vector into the vector defining the hyperplan and then you see if the length of you projected vector is before or after the hyperplan and this is how you define your two classes.
This is very simple way of seeing it, and then you can go into more details by following some papers or videos.

Python: Fit geometric forms into a board matrix? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
In the past few days i was thinking of a solution for an AI problem. The problem sounds like this:
I want to determine an arrangement for a few given geometric forms(that do not exceed the given board size) on a square board of given size, in such a way that the board will be uniform covered and the forms will
not overlap.
I want to apply Depth first search / Greedy best first search, but it feels difficult to find a proper representation of the forms and the actual board in order to traverse it. I'm new to python so that makes it a bit more difficult. Any suggestions?
Visual example:
What you are describing is a variation on rectangle/square fitting. Versions of the problem exist where unused cells have to be minimised for an optimal placement of the figures, whereas other versions, like the one you are describing, require for the whole board to be covered uniformly. These are called 'perfect square/rectangle placement' problems.
Typical ways to solve these problems involve the usage of finite integer domains representing the variables of the rectangles and a set of constraints making sure the geometrical placements are valid ones (i.e. don't cross the board borders, don't overlap with each other mutually, ..).

What are possible methods for creating a physical engine [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
This is a general question that comes to answer an issue that interests me for general knowledge and not to answer a specific problem.
I was wondering what are the available ways to implement a physical engine where objects interact with each other and with outside forces. As an example we can look at Angry Birds, or games like TIM. Where there are objects that "fly" through the air, collide and interact with each other, and are affected by the potential of the environment like gravity, winds and other "forces".
The model that I have thought about is that each object has an object (as an object of some class) and a thread that relate to it. Each time slot the thread get it "advances" the object in the space for some small dt. In this case you could have an "environment" object that can get a position in space and give you the equivalent force that is applied by the environment potential. What I can't exactly get is how the objects interact with each other?
Also, am I close in my direction? Are there other solutions and models for those problems, and are they better? What are the things I'm missing (I must be missing some things)?
the implementation is typically nothing like you describe, which is way too expensive. instead, everything is reduced to matrix transformations. points are lists of coordinates that are operated on by matrices that update them to the next time interval. the matrices are themselves calculated from the physics (they are a linear solution of the forces at that moment, more or less).
things get more complicated when you have very large differences in scale (say, for simulating stars in a galaxy). then you may use a more hierarchical approach so that critical (eg fast moving or, more accurately, strongly accelerating) points are updated more often than non-critical points. but even then the in-memory representation is very abstract and nothing like as direct as "one object per thing".

Resources