Python Forum
Issue with Dynamical Models course
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Issue with Dynamical Models course
#1
Hi Guys,

I would like to ask a help for my homework Angel
I hope I did an understandable translation for the task.

Thanks in advance:
Cilyt


Optional task for 1 point: Background

A land is divided into 10x10 plots (that means there are 10 plots in each row and there are a total of 10 rows) and we are growing plants in each plot.
We are working on the following simple model:
– The plots initially contain 0.1 units of plants.
– [growth phase] in each plot, the amount of plant increases by a random number between 0.0 and 0.2 in each time unit.
– [harvesting phase] if, by the end of the growth phase, the amount of plant in a plot increases above 1.1, then harvest the contents of the plot so that the remaining quantity is 0.1 (so it is possible that the quantity of harvested is a number above 1).


Optional task for 1 point: Task

Implement the above model in a class called Simulation, which will require the following member variables:
height: an integer, in this problem is 10.
width: an integer, in this problem is 10.
actual_state: a 10x10 table that showing the current state of the land.
harvest: a list that stores the quantities of harvested (initially empty list).

We implement the following functions:
run(time):
– Input parameter: time, this specifies the number of time units, meanwhile the simulation is running.
– Implements the simulation, i.e.
1. Performs the growth and harvest phases for each time unit and cell.
2. Saves the crop (that is, the quantities harvested) to the harvest variable.
3. Saves the end state of the time unit end to the actual_state variable.

statistics(): returns after the simulation:
– The number of harvests.
– The largest harvested crop

Notes:
– The implementation of the function generating the initial state is given.
– In the run function, a triple for loop implements the simulation (time, rows of land, columns of land).

Have to do on:
http://colab.research.google.com

# Homework

[1]
import matplotlib.pyplot as plt


class Simulation:
    def __init__(self):
        self.width = 10
        self.height = 10

        self.actual_state = self.init_first_state()

    def init_first_state(self):
        init_state = []
        for x in range(self.height):
            row = []
            for y in range(self.width):
                row.append(0.1)
            init_state.append(row)
        return init_state

    def run(self, time):
        pass

    def statistics(self):
        harvest_amount = None
        maximal_harvest = None
        return harvest_amount, maximal_harvest
[2]
if __name__ == '__main__':
    # Create Simulation instance
    sim = Simulation()
[3]
if __name__ == '__main__':
   # Run simulation
    sim.run(100)
[4]
if __name__ == '__main__':
  # Plot last state
    plt.imshow(sim.actual_state, cmap='Blues')
    plt.colorbar()
    plt.show()
[5]
if __name__ == '__main__':
    # Print statistics
    amount, max_harv = sim.statistics()
    print('Number of harvests:', amount)
    print('Maximal harvest:', max_harv)
Do you have any idea how next?
Reply
#2
You had best start to implement the run() method on line 20.
Iterate over the rows and columns of "actual_state". For each value: get a random value between 1.0 and 1.2 and multiply actual_state[row][column] with that random value.
Try to show the begin and end situation.
Does it work? Then repeat those steps "time" times.
Does it work? Then do something with harvesting.

Let us know when you come across something you can't solve. Then we will help you further.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Advanced Algorithms and Computational Models hafedh 4 2,284 Aug-31-2020, 06:37 PM
Last Post: buran
  Tricky estimating three models and creating a table: regression HellinPython 1 2,726 Oct-18-2017, 02:46 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020