Questions tagged [simulation]

Simulation is the imitation of some real thing, state of affairs, or process. The act of simulating something generally entails representing certain key characteristics or behaviours of a selected physical or abstract system.

Filter by
Sorted by
Tagged with
8 votes
3 answers
2k views

OOP Critter Caretaker program from "Learning Python for the Absolute Beginner"

I'm currently learning programming and Python from Python Programming for the Absolute Beginner, Third Edition. I've been doing the challenges set out at the end of each chapter but I'm never sure if ...
strainsrain's user avatar
-4 votes
1 answer
8k views

Python PID simulator controller output [closed]

I have written a piece of code (in Py3) that graphs out the controller value of PID controller. This is so that by changing the various sub controllers (P/I/D) I can visualise how the graph changes. I'...
3kstc's user avatar
  • 125
5 votes
3 answers
3k views

Python election challenge

Basically, there is an election on 3 regions where either candidate needs to win 2 in order to win the election. Idea is to simulate 10000 elections to see which candidate wins. I think my solution ...
Kimmo Hintikka's user avatar
17 votes
3 answers
277 views

"Do I understand the gravity of the situation?"

What is this? This is a two-dimensional physics simulator that models gravity and collisions between circular objects (though it doesn't model rotation). How do you use it? You can tweak the following ...
Thriggle's user avatar
  • 1,308
6 votes
2 answers
329 views

Thread worker simulator

Because I have been writing more multithreaded C++14 code lately, I've developed some tools that help me make sure that my threads are all working as intended. In the real code, it's often difficult ...
Edward's user avatar
  • 65.3k
4 votes
1 answer
171 views

Epidemic simulation over a large population

This is a follow-up to my question about epidemic simulation. The accepted answer works, but also mentions that I should look at modifying the external_function_call. Here's the complete working code, ...
StatsSorceress's user avatar
6 votes
1 answer
384 views

Simple Bus Network simulation

I am simulating a simple bus network (as shown in the picture) using event simulation. There are two buses running (starting at 1 and 4) and the travel time between nodes is 10 units. For now, I used ...
Rocky's user avatar
  • 63
2 votes
1 answer
317 views

Monty Hall simulator in Python 3.x

I've been working on Python for the past few weeks trying to get my head around it's syntax/naming conventions/style/etc. I decided to make a monty hall sim to see how it looks in python. For those ...
ephreal's user avatar
  • 105
8 votes
2 answers
1k views

Epidemic simulation

The purpose of this code is to simulate epidemics across a population. There are 625 (pop) individuals at random locations. The epidemic parameters are infectious period (inf_period), trans (...
StatsSorceress's user avatar
3 votes
2 answers
2k views

Percolation using quick union connectivity algorithm

This is my attempt to solve the percolation problem for the Princeton Algorithm-I course, the problem is well-defined here. My implementation is in C++ not Java and the following procedure is followed:...
Algo's user avatar
  • 339
2 votes
1 answer
135 views

Loop combinations of byte for Poker simulator

In (this) Poker you have 2 hole cards that are combined with 5 shared cards on the board. Each player makes the best 5 card hand from the seven. Believe it or not that is over 2 billion runs to do ...
paparazzo's user avatar
  • 5,946
2 votes
0 answers
4k views

Barrier Option Pricing using Python

This is my implementation of pricing an exotic option (in this case an up-and-in barrier option) using the Monte Carlo simulation in Python. I use NumPy where I can. Any ideas to optimize this code? <...
DudeWah's user avatar
  • 161
2 votes
0 answers
122 views

Sorting overlapping shells in dynamical simulation - for loops vs array methods

I didn't know whether it was best to start with the general task I'm trying to solve, or the meat of the programming problem. They're both below but the former is rather long and solving the latter ...
zephyr's user avatar
  • 143
4 votes
0 answers
2k views

Monte Carlo simulation to price an Option in Python

In what ways can I make this code more efficient? I haven't put in comments and descriptions yet. I need to do that. Ideally, I'd like to make the S, v, r, and K user entered as I did with T. I'm ...
DudeWah's user avatar
  • 161
2 votes
1 answer
1k views

Compute the probabilities of getting each of the possible sums when throwing 2 dice, n times

I'm struggling with some coding-inexperience. The code I've written below, is extremely inconvenient and ugly to look at. My question to you is: How can this be done more efficiently? The way I've ...
FrenziedMango's user avatar
6 votes
3 answers
11k views

Slot Machine Simulator

I'm studying alone, so I don't know if I'm writing efficiently. Could this slot machine simulator be improved? How? ...
Guilherme's user avatar
  • 277
4 votes
2 answers
176 views

Birthday Paradox Tester

I randomly decided to write a program that tests the Birthday Problem/Paradox. The gist of the problem/paradox is that if you have a group of people in a room, how many people are required for there ...
Carcigenicate's user avatar
4 votes
3 answers
2k views

Tic-Tac-Toe game simulator in Java

I've completed this Tic Tac Toe simulator in java and so far it's working. It's just supposed to generate a pre-played game and announce the winner. I'm required to use a 2D array and this is the way ...
Allie Marie's user avatar
2 votes
0 answers
86 views

Simulation of reflected particles

I made a particle simulation in vanilla JavaScript. It can currently handle around 10000 particles (staying 58-60 fps on my machine). For testing, controls are MB1, MB2, R, Z. How can I make this ...
user3050748's user avatar
9 votes
1 answer
625 views

Monty Hall Optimization in Python 3.5

This is for homework but the deadline is over and I know the implementation is correct because it concurs with the math. At this point I just want to check my implementation for potential ...
jeremy radcliff's user avatar
9 votes
1 answer
3k views

ALOHA network simulation in Python

I'm currently studying the book From Algorithms to Z-Scores: Probabilistic and Statistical Modelling in Computer Science In the first chapter of the book the ALOHA network protocol is introduced as ...
Sorrop's user avatar
  • 297
5 votes
1 answer
1k views

Multigeneration evolution simulator, graphing phenotypic change

I created an evolution simulator. It takes random chance and applies it to phenotypes of species. This was very much for fun, and I would love any input on: Readability of code Efficiency of ...
Joseph Farah's user avatar
13 votes
4 answers
4k views

Simulating a printer

I'm trying to recreate a printer in Java. I'm fairly new to programming so I'm using huge if/else blocks inside a single ...
PacketSniffer's user avatar
3 votes
2 answers
2k views

Betting strategy simulation

I lately got interested into betting systems, dice strategies and algorithms. I took some time to think about it and eventually ended up with an algorithm of my own. Considering that I don't have ...
Maxime B's user avatar
4 votes
2 answers
2k views

Processing simulation data from power flow analysis

The intro is a bit long. If you're not interested, then please read the update, and have a look at the specific parts I'm highlighting. I'm very interested in any improvements, but you can assume ...
Stewie Griffin's user avatar
5 votes
3 answers
137 views

Statistical Analysis of X-Wing Game Dice

I was in a discussion about mechanics of the X-Wing miniatures game where we were discussing a couple of the ways to improve attacks and I put together this small C# console application to determine ...
Evan Frisch's user avatar
1 vote
1 answer
9k views

First time ATM machine program

I have created a gorgeous ATM machine program. It makes all other ATMs look like crap, if I do say so myself. What I would like is some sort of critique on what I've done: Is there better syntax I ...
YoYoYo I'm Awesome's user avatar
2 votes
0 answers
446 views

Comparing three packet routing algorithms via simulation in Java

Inspired by my question Simulating a random packet routing algorithm and printing packet statistics in Java I decided to implement two more packet routing algorithms: one that computes all the ...
coderodde's user avatar
  • 27k
23 votes
5 answers
2k views

Benchmarks of various scientific programming languages for theoretical modelling

For a theoretical modelling course for biology students, I am trying to decide which would be the best technical programming language for doing evolutionary simulations in terms of elegance and ...
Tom Wenseleers's user avatar
3 votes
2 answers
917 views

Simulating a random packet routing algorithm and printing packet statistics in Java

I have this short program for simulating a random packet routing algorithm: Packet.java ...
coderodde's user avatar
  • 27k
5 votes
1 answer
5k views

Dice simulation and counting pairs

This is my first time putting a code together for Java based on my own so i was hoping if you someone would be kind enough to review and provide feedback or constructive criticism on this code. The ...
Java n00b's user avatar
1 vote
1 answer
73 views

Income Simulation programifier

http://pastebin.com/7UqD0gwF I'm looking for serious feedback on my first serious program. This is a program to calculate PvZ income over time of sunflowers and sunshrooms on nighttime pool levels. ...
Yongus's user avatar
  • 71
2 votes
0 answers
495 views

Physical simulation of diffusion-limited aggregates

The following code generates Diffusion Limited Aggregates on a two-dimensional square lattice. Some of the code has been omitted (e.g. support for differing lattice types and dimensions) for code-...
sjrowlinson's user avatar
4 votes
1 answer
216 views

Virtual Lotto Task

I had the task to write a Lotto simulator. My program works as follows: To start, the user can type in 6 numbers. Then the winning numbers are randomly chosen. The program then shows the winning ...
djaszak's user avatar
  • 315
5 votes
2 answers
703 views

Monte Carlo simulation of amoeba population

I wrote a simple Python simulation to answer the "Amoeba" population question posed here: A population of amoebas starts with 1. After 1 period that amoeba can divide into 1, 2, 3, or 0 (it can die)...
Roberto's user avatar
  • 273
4 votes
3 answers
473 views

Hungry ant AI: any food here?

I'm working on a little AI to simulate ants (very basic). The full code can be found on Github. This function (in Ants.py) takes a list of Tuples containing ...
Patrick Greene's user avatar
2 votes
0 answers
615 views

PHP Lottery Simulator

I have a lottery simulator on my website that simulates you playing the lottery every week until your death and tells you how much you would have won or lost. It can take a custom number of balls and ...
Qiri's user avatar
  • 141
3 votes
1 answer
401 views

Sleeping barber problem in Erlang

I'm learning Erlang. It's my first time with a non-imperative programming language. I've written a code and I want some thoughts about it: Is my logic easy to understand? Is my code idiomatic? Is my ...
Gabriel's user avatar
  • 1,053
1 vote
1 answer
296 views

Particle in Cell: efficient data structure handling

I am building a simulation where you have 'Agents' distributed over a rather large landscape. Because the number of Agents is small, compared to the size of the landscape, I use the PIC approach where ...
Sebastian Lehmann's user avatar
2 votes
1 answer
70 views

Distributed (asynchronous) averaging

This code simulates a distributed averaging protocol. There is a network of nodes, and at the clicks of a Poisson process: A random node wakes up Transmits it's current average to all the nodes it is ...
Tom Kealy's user avatar
  • 505
6 votes
1 answer
258 views

Circuit Simulator

I'm trying to learn Golang from Java, and to do this, I wrote a basic circuit simulator with only two circuits. Is there anything I can do better to make it more idiomatic? Simulator.go ...
Kyranstar's user avatar
  • 1,189
2 votes
2 answers
1k views

Random positioning and movement of a rabbit on a table

I was inspired by this: If you would put a rabbit randomly on a circular table with radius r= 1 meter and it moves 1 meter in a random direction, what is the chance it won't fall off? I ...
jdrd's user avatar
  • 23
12 votes
2 answers
1k views

Gravitational Brute Force N-body Algorithm

I've just started dabbling with code, and as a learning exercise I've written a simple algorithm for solving gravitational n-body problems numerically in JavaScript. I would be very grateful for ...
Happy Koala's user avatar
6 votes
2 answers
973 views

Distributed system simulator

I have coded a very simple distributed system simulator in Python. It uses multiprocessing to assign tasks, and queues to communicate between processes. The code is shown below. ...
Haris's user avatar
  • 113
2 votes
2 answers
81 views

Generating time series for generator ON or OFF

Want to create time series for the nuclear power plant performance using the equation for Time to fail and time to repair for 8736 hours in the year so that I have the time series in hours when the ...
kelamahim's user avatar
  • 155
4 votes
2 answers
239 views

Functional translation of dice simulation

I have tried my hands at "functionalising" a toy problem I had: find the expected number of throws of a six sided die until all sides have been seen (the answer is 14.7) My starting point is my ...
luffe's user avatar
  • 143
5 votes
2 answers
303 views

Attempting to run multiple simulations of the Gillespie algorithm for a set of stochastic chemical reactions in less than 10 minutes

I have written Python code that generates a plot. In the code below, when I set maxtime = 0.1, the program takes ~50s and when I set ...
abscissa's user avatar
6 votes
1 answer
378 views

Approximating π via Monte Carlo simulation

Inspired by a tweet linked to me by a friend and a Haskell implementation by her for the same problem, I decided to try my hand at approximating the value of π using everything in the Haskell standard ...
Alexis King's user avatar
  • 3,172
11 votes
1 answer
2k views

Lotto simulator

With the recent craziness of the Powerball in the US, I got interested in building a little lotto simulator to see how frequently I could win with purchasing large amounts of tickets. For those not ...
Jared Mackey's user avatar
7 votes
2 answers
108 views

Quite-Off-The-Bat Complex Console Ant Colony Simulator w/ Partial AI

As a follow-up of my previous non-off-the-bat Ant Colony Simulator, we have this one that works off-the-bat... quite; the code for when the ants find and take the food isn't really done but it would ...
wallabra's user avatar
  • 779

1
4
5
6 7 8