KOL答疑– FAQ:UNSW 1811 Python Assignment 2: Simulation and Design of Biofuel Production

以下为ass2 的题目,答疑专区在最后区域,请拉至后面区域查看精彩问答。

欢迎随时提出问题,本平台给予免费的咨询回答服务,互联网大牛们在等你哦~~!

请加微信:HYPdear

或扫描二维码即可免费咨询:

Introduction

We often think bacteria are bad. The truth is that there are many different types of bacteria in this world. Some bacteria are harmful to humans but some bacteria in our bodies help us to live. Have you ever considered the possibility that bacteria can also be “factory workers”? Engineers and scientists are working on using bacteria to produce certain chemicals and materials. An example is to use bacteria to produce fuel for us. In engineering, we often want to optimise the process, so we may want to make the bacteria to produce as much fuel as possible in a given time. However, there are often constraints in nature. The truth is that fuel is toxic to bacteria, so we need to find a way for the bacteria to make a lot of fuel but at the same time keep them alive! This biofuel production process is the theme of this assignment.


The aim of this assignment is to give you an opportunity to work on a small-scale engineering design problem in python. The engineering system that you will be working on is biofuel production. Your goal is to determine the design parameters so that the bacteria can produce as much fuel as possible while respecting a couple of constraints. You will use simulation as part of the design process.

For this assignment, you need to work in a group of two with the restriction that your group partner must come from the same lab class (i.e. same lab time slot and lab room). If you want to work on your own, please check with your tutor.

 

Learning objectives

This assignment is designed to give you practice in

  • Applying programming to solve a simple engineering design problem
  • Writing a python program to simulate an engineering system
  • Applying a number of python features, which include arraytorisation, built-in functions and others
  • Applying good software engineering practices, which includes proper documentation, program style
  • Working with a partner (if applicable)

Assignment overview

This assignment is design to imitate engineering design. You will see the following elements:

  1. (Simulation) Simulation of a biofuel production system with different design parameters.
  2. (Design)Evaluate the performance of the systems that you have simulated.

Download files: There are a number of python files that you need to do this assignment. These files are in assign2.zip. We will first talk about the tasks involved, and later introduce these supplied files, see Supplied Files for more.

We will first give an introduction to biofuel production. This introduction is meant to give you some intuition on the design problem. After that we will tell you what you need to do for the assignment.

Biofuel production process

We will give you a basic mental picture that you can use to visualise biofuel production. A pictorial representation of a bacterium is in Figure 1. A bacterium is a single-cell organism. It has a cell membrane, which you can think about as the “skin” of a bacterium. By using bioengineering, we can get the bacteria to produce fuel for us. This production will take place within the bacteria, i.e. inside the cell membrane of the bacteria.

Figure 1. A pictorial depiction of the main elements of a bacterium for biofuel production. 

 

Now that you know that fuel is produced inside the membrane of bacteria, the next thing you need to know is that having the fuel staying inside the bacteria is neither good for us nor the bacteria. It is not good for us because we cannot collect the fuel. It is not good for the bacteria because it is toxic to them. This means we need a way to get the fuel from the inside of the membrane to the outside. A good news is that bacteria can make efflux pumps on the membrane to push the fuel from the inside of the membrane to the outside.

With these efflux pumps, we can reduce the amount of fuel in the bacteria (i.e. toxicity level) and collect the fuel, solving the problem that we talked about in the last paragraph, but there is one catch. Efflux pumps, though useful, can be a burden to the bacteria. This means that a bacterium should not have too many efflux pumps. A clever way is to get the bacteria to make efflux pumps on demand. If a bacterium senses that there is a lot of fuel inside its membrane, it should make more efflux pumps to expel the fuel; and vice versa. With the help of bioengineering, it is possible to have biosensors in bacteria to sense the amount of fuel in the bacteria.

The above mental picture should give you the intuition you need for the biofuel production process. In order to do engineering design, we need a mathematical model which we will discuss next.

A mathematical model for the biofuel production process

From the biofuel production description that we have discussed above, you know that we are interested in a few quantities: the amount of biofuel inside the bacteria because this is related to the toxicity level; and, the amount of biofuel outside the bacteria because this is the amount that we can collect. We would like to have a mathematical model which tells us how these two quantities vary over time. The mathematical model can tell us how the following five quantities vary over time:  

  • The amount of bacteria in the colony denoted by the mathematical symbol n. Note that we scale the amount by the maximum possible of bacteria so nis a number in the interval [0,1].
  • The biosensor output denoted by Rwhich is a non-negative real number.
  • The amount of efflux pumps, denoted by p, which is a non-negative real number.
  • The amount of biofuel in the interior of the bacteria, denoted by bi, which is a non-negative real number. We also call this internal biofuel.
  • The amount of biofuel in the exterior of the bacteria, denoted by be, which is a non-negative real number. We also call this external biofuel.

You will use simulation to determine these five quantities.

There are two design parameters which we will vary, they are:

  • The biofuel production rate αb. (python variable name alpha_b)
  • The efflux pump production rate αp. (python variable name alpha_p)

We have placed the mathematical model for the biofuel on a separate page. We believe it is best for you to understand what you need to do for this assignment first before dwelling into the mathematical model. You should be able to understand what you need to do for the assignment without going into the mathematical model at this stage. (The model is here and you can read it later.) The mathematical model for biofuel production is based on Reference [1].

Overview of tasks

We have divided the work into a number of tasks.

  • Task 1: Task1A is on simulation and Task 1B evaluates the system constraints
  • Task 2: is on engineering design (which also has Parts A and B)

Task 1A: A python function to simulate the biofuel production system

The aim of this task is to write a python function sim_biofuel (which should be in a file with name sim_biofuel.py) to simulate the biofuel production process. You can find a template for this function in sim_biofuel_template.py (in assign2.zip). You should rename it as sim_biofuel.py before you start. The declaration of the function sim_biofuel is:

def sim_biofuel(data_set_to_use, time_array, init_bacteria_amount, alpha_b, alpha_p) :

The above function returns five arrays. All these five arrays should have the same length as the input array arrayTime. These five arrays contain the following simulation outputs:

  • bacteria_amount_array for the amount of bacteria n
  • sensor_array for the biosensor output denoted by R
  • pump_array for the amount of efflux pumps p
  • biofuel_int_array for the amount of biofuel in the interior of the bacteria bi,
  • biofuel_ext_array for the amount of biofuel in the exterior of the bacteria be,

The inputs are:

  • data_set_to_use is an integer indicating data set to use containing constants you need for simulation.
  • time_array is a array of time instances that you need for simulation.
  • init_bacteria_amount is a scalar for the initial amount of bacteria in the colony.
  • alpha_bis a scalar for the design parameter for biofuel production rate  αb
  • alpha_pis a scalar for the design parameter efflux pump production rate αp

The implementation of sim_biofuel requires the mathematical model for the biofuel production process. (The model is here and the suggestion is that you read the model later.)

Hint: You can use the python simulation program para_ODE_ext_lib.py and para_speed_height_by_ODE.py (code from Week 7’s lecture) or the material from “Lab 08: Simulation and its applications” as a starting point to develop the function sim_biofuel.

The only non-zero initial condition is the amount of bacteria. This is defined by the constant INITIAL_BACTERIA_AMOUNT, which is specified in the simulation data set. The python files provided for testing load this constant in for you, so you can assume this constant is available and use it. You can assume the initial conditions for R, p, bi and be are zero.

The array time_array is a uniformly spaced array of time instances. The start and end times, as well as time increments, are specified in the simulation data set. The python files provided for testing your function load these constants in for you, as well as define the array time_array. So, you can assume the time array is available and use it.

When you call the function sim_biofuel, the only inputs that you need to adjust are the values of alpha_b and alpha_p. For example, if you want to do simulation with αb = 0.1 and   αp = 0.6, you should use:

def sim_biofuel(data_set_to_use, time_array, INITIAL_BACTERIA_AMOUNT, 0.1, 0.6) :

Note that you can leave the first three inputs (shown in red) as they are shown in the above line. You may want to read through the file test_1A_1B.py to give you an example on how to call the function.

You can use the python program test_1A_1B.py (in assign2.zip) to test your sim_biofuel. The program test_1A_1B.py first reads in the constants and parameters for the selected data set. It then creates an equally spaced array time_array. The program then calls the function sim_biofuel to compute the five outputs of the simulation, and compares them to the reference values. If you see the error is small, i.e. less than 10-6, then your sim_biofuel should be working correctly.

Note that we have provided two different sets of system and simulation parameters. You can choose between them by assigning the variable data_set_to_use to either 1 or 2. You can find this variable near the beginning of the file. For each system parameter set, you can use three different pairs of design parameters in test_1A_1B to test your data_set_to_use. The selection is done by setting the variable test_indexto 1, 2 or 3.

Task 1B: A function to calculate the maximum and the amount of oscillation in the level of internal biofuel

We have mentioned earlier that biofuel is toxic to the bacteria. It would be desirable if we can choose our design parameters αb and αp to limit the maximum amount of biofuel inside the bacteria. This is one design constraint that we want to impose.

There is another design constraint that we would like to impose. Let us first illustrate it. Depending on the choice of the value of αb and αp, the amount of biofuel in the bacteria can vary differently over time during the biofuel production process. Figure 2 shows how the amount of internal biofuel varies over time for αb = 0.0162 and αp= 0.07, with Parameter Set 1. We can see that the amount of biofuel increases steadily from zero.

Figure 2: Amount of internal biofuel against time for αb = 0.0162 and αp= 0.07.

Figures 3 shows what happens if we use αb = 1 and αp= 0.05 instead. We see that the amount of biofuel in the bacteria oscillates for these design parameters. This may not be good for the bacteria because they have to make efflux pumps which they later do not need. This is undesirable.

Figure 3: Amount of internal biofuel against time for αb = 1 and αp= 0.05.

For our design, we would like to find design parameters which limit (1) The maximum amount of internal biofuel; and, (2) The amount of oscillation in the level of internal biofuel. We want to do this quantitatively. Let us assume that you have done the simulation and have the amount of internal fuel stored in the array biofuel_int_array. The maximum amount of internal biofuel is then the maximum value in the arraytor biofuel_int_array. To determine oscillation, we use the following algorithm:

  • Determine the maximum value in biofuel_int_arrayand we will call the maximum value max_biofuel_int
  • If max_biofuel_intis the last element of biofuel_int_array, then the amount of oscillation is zero. This is the situation of Figure 2.
  • If max_biofuel_intis not the last element of biofuel_int_array and let us say it is the k-th element of the array. We determine the minimum value of biofuel_int_array from the (k+1)-th element till the end of the array and let us call this value min_biofuel_int. The amount of oscillation is max_biofuel_int minus min_biofuel_int. This is the situation in Figure 3. An illustration of the meaning of max_biofuel_int and min_biofuel_int is in Figure 4.


Figure 4: Illustration on the amount of oscillation. 

In this task, your job is to write a python function find_max_and_oscillation with declaration

def find_max_and_oscillation(input_array) :

The aim of the function is to determine (1) The maximum value in input_array and output it in max_value; and (2) The amount of oscillation in input_array and output it in oscillationSize. The function returns these two values (i.e. return max_value, oscillationSize).

A requirement for Task 1B is that you cannot use any loops in this function. You can only get full marks if you do not use any loops. If you use loops, you will receive a reduced mark.

You can test this function by using the script test_1A_1B. The lines for testing this function is commented out initially. You need to remove the # sign in order to get the testing going. If you adjust the value of the variable test_index, you can choose between 3 different set of design parameters.

Task 2A: Calculating the design objective and constraints for many pairs of (alpha_b, alpha_p)

You have seen that different values of αb  and αp can lead to different behaviour of internal biofuel level. In the same way, different values αb  and αp can lead to different amount of fuel that we can collect. Our design objective is to collect as much fuel as possible at the end of the production process. We can measure this design objective quantitatively by using the value of the last element of the array biofuel_ext_array, which represents the amount of external biofuel at the end time of the simulation.

In this task, you will use many different pairs of (alpha_b, alpha_p) for simulation. For each pair of (alpha_b, alpha_p), you will simulate the biofuel production and use the output of the simulation to determine: (1) The amount of biofuel you can collect; (2) The maximum amount of internal biofuel; and, (3) The amount of oscillation of the internal biofuel.

The steps for this task are:

  1. Create an array of alpha_p_arrayof equally spaced αp values. The first value is ALPHA_P_LOWER and the last value is ALPHA_P_UPPER with an increment of ALPHA_P_STEP. These three constants are specified in a parameter set that the program test_2A.py reads in. You can use them directly. Note that the program also has a line which creates an array alpha_b_array of αb values. You can use that.
  2. Create three zero matrices whose number of rows is the number of elements in alpha_b_arrayand the number of columns is the number of elements in alpha_p_array. You should call these three matrices max_internal_biofuel,  oscillation_internal_biofuel and final_external_biofuel.
  3. Perform simulations for all possible pairs of (alpha_b, alpha_p)where alpha_b comes from the elements in alpha_b_array and alpha_p comes from the elements of alpha_p_array. For each pair of (alpha_b, alpha_p), we need to do the following:
    • o The (i,j) element of the matrix max_internal_biofuel, i.e. max_internal_biofuel(i,j), should be assigned the maximum amount of internal biofuel when alpha_b_array(i) andalpha_p_array(j) are used.

For example,

  • o
  • o The (i,j) element of the matrix oscillation_internal_biofuel, i.e. oscillation_internal_biofuel(i,j), should be assigned the amount of oscillation in internal biofuel whenalpha_b_array(i) and alpha_p_array(j) are used.
  • o The (i,j) element of the matrix final_external_biofuel, i.e. final_external_biofuel(i,j), should be assigned the amount of biofuel that can be collected when alpha_b_array(i) andalpha_p_array(j) are used.

In this part you need to implement the following function:

def generate(data_set_to_use, time_array, INITIAL_BACTERIA_AMOUNT, alpha_b_array, ALPHA_P_LOWER, ALPHA_P_UPPER, ALPHA_P_STEP) :

Input:

  • data_set_to_use, time_array, INITIAL_BACTERIA_AMOUNT, alpha_b_array, ALPHA_P_LOWER, ALPHA_P_UPPER, ALPHA_P_STEP

Output:

  • alpha_b, alpha_p, max_internal_biofuel, oscillation_internal_biofuel, final_external_biofuel

You can use the file test_2A.py to check whether you have calculated the three matrices max_internal_biofuel,  oscillation_internal_biofuel and final_external_biofuel correctly.

Task 2B: Engineering design

The engineering design problem is to choose good design parameters to meet our design requirements. In our case, a design has two design parameters alpha_b and alpha_p.  In Task 2A, you have associated each design, or each pair of (alpha_b, alpha_p), with three quantitative measures:

  • Amount of biofuel that can be collected
  • Maximum amount of internal biofuel
  • Amount of oscillation of internal biofuel

We want to choose the best pair of (alpha_b, alpha_p) base on these three quantitative measures. We know that large amount of internal biofuel and large amount of oscillation are undesirable. What we want to do is to impose an upper limit on each of these two quantitative measures. We introduce two thresholds:

  • THRESHOLD_MAX_INTERNAL_FUEL is a threshold on the maximum amount of internal biofuel
  • THRESHOLD_MAX_OSCILLATION_INTERNAL_FUELis a threshold on the oscillation of internal biofuel

These two constants are specified in a parameter set that the program test_2B.py reads in. We say that a design is acceptable if

  • Maximum amount of internal biofuel is less than or equal to THRESHOLD_MAX_INTERNAL_FUEL, and
  • The amount oscillation of internal biofuel is less than or equal to THRESHOLD_MAX_OSCILLATION_INTERNAL_FUEL

Out of all the designs that are acceptable, we will choose the design that allows us to collect the largest amount of biofuel. We will call this design the best design.

For comparison purpose, we will also determine a poor design which we define as the design that maximises the amount of biofuel that can be collected, without considering any constraints.

Once you have obtained the best design and the poor design, you need to return these four values from the following function you need to implement for his part.

A requirement for Task 2B is that you should complete this task without using any loops. You can only get full marks if your solution does not use loops. If your solution requires loops, then you can only get a reduced mark.

In this part, you need to implement the following function:

def design( THRESHOLD_MAX_INTERNAL_FUEL, THRESHOLD_MAX_OSCILLATION_INTERNAL_FUEL,
alpha_b, alpha_p,
max_internal_biofuel, oscillation_internal_biofuel, final_external_biofuel) :

Output (return values):

  • best_alpha_b, best_alpha_p, poor_alpha_b, poor_alpha_p

You should be able to determine whether your answers are correct by manually checking on the elements of the matrices. You can do that. The matrices are big so you may want to come out with some smaller matrices yourselves to test your work. We strongly encourage you to do that because it is always good to try to check your own work. When you go out to work, you will need to check your own work. We have also placed the answers here but we encourage you to check your own work before looking at them.

Remark: We have used exhaustive search here to determine the design parameters. This is certainly not the most efficient algorithm but you will learn better optimization methods in later years.

Style

You should make sure that all your files are properly documented with appropriate comments. Variables that you use should have well chosen names and their meaning explained. Appropriate style should be used.

Supplied Files

The supplied files are (in assign2.zip):

  • The file sim_biofuel_template.pyis for Task 1A. You should rename it as sim_biofuel.py
  • For Task 1B, you need to create file find_max_and_oscillation.pyfor the function find_max_and_oscillation
  • For Task 2A, you need to create file generate.pyfor the function generate
  • For Task 2B, you need to create file design.pyfor the function design

We have two sets of parameters. You can choose between the two sets of parameters by using the variables data_set_to_use. Each set of parameters is made up of constants in two files:

    1. System parameters which are the constants you need for the mathematical model in biofuel_system_parameter_sets.py.
    2. Simulation and design parameters in biofuel_simulation_design_parameter_sets.py.
  • Files for testing
    • o test_1A_1B for testing Tasks 1A and 1B.
    • o test_2A for testing Tasks 2A.
    • o test_2B for testing Tasks 2B.
    • o These files require support files, which are pickleand set2_check.pickle files.

Assessment

The following table shows the maximum possible marks for the tasks. Note that, for Tasks 1B and 2B, you can only get full marks if your solution does not use any loops; otherwise, a reduced mark will apply.

Marks   Feature/Assessable Item
            6   Task 1A (Function sim_biofuel)
            6   Task 1B (Function find_max_and_oscillation. Reduced maximum: 1.5
            6   Task 2A (Correct max_internal_biofuel,  oscillation_internal_biofuel and final_external_biofuel)
            6 Task 2B (Correct values of alpha_b and alpha_p for the two designs). Reduced maximum: 1.5
3   Style, complexity, etc. (Comments; Variable definitions; Style; Complexity)
27   Total mark (rescaled to 10% of overall assessment)

Groups and submission

This assignment is to be completed in a group of two with the restriction that your group partner must come from the same lab class (i.e. same lab time slot and lab room). If you want to work on your own, please check with your tutor.

You must register the pair with your tutor no later than the Week 11 lab class.

complete submission should contain the following four files (as described above):

  1. sim_biofuel.py
  2. find_max_and_oscillation.py
  3. generate.py
  4. design.py

The submission system will accept the above four filenames.

Submission system will be available in week-12.

Only one member of a pair should submit, as the submission is stored against the group rather than the individual, and each member will receive the mark awarded to the group.

Originality of Assignments

As with all material submitted for assessment, this must be substantially your own registered group’s work. It’s OK to discuss approaches to solutions with other students, and to get help from tutors and consultants, but you must write the Basic code yourself. Sophisticated software is used to identify submissions that are unreasonably similar, and marks will be reduced or removed in such cases.

Further Information

Use the forum to ask general questions about the assignment, and keep an eye on it for updates and responses.

 

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
 ENGG1811 Assignment 2 
 Purpose: You can use this program to testthe following function from task 2A:
 (1) generate
 
"""
import numpy as np 
import pickle
import biofuel_simulation_design_parameter_sets as bsdps
import generate as gn

# Use the variable dataSetToUse to choose which parameter set you
# want to use
data_set_to_use = 1 # Either 1 or 2 
#

# PLEASE DO NOT CHANGE THIS SECTION
# BEGIN - DO NOT CHANGE 
# The following line reads in the simulation parameters for data_set_to_use,
# For example: time increment and other parameters you need for simulation
simulation_design_para = bsdps.biofuel_simulation_design_parameter_sets(data_set_to_use)

# Initial (normalised) amount of bateria 
INITIAL_BACTERIA_AMOUNT = simulation_design_para['INITIAL_BACTERIA_AMOUNT' ] 
# Simulation start and end times, simulation time interval
TIME_START = simulation_design_para['TIME_START' ] # Start time
TIME_END = simulation_design_para['TIME_END' ] # End time
TIME_DELTA = simulation_design_para['TIME_DELTA' ] # Delta t 
# alpha_b: Lower and upper limits, number of points 
ALPHA_B_EXP_LOWER = simulation_design_para['ALPHA_B_EXP_LOWER'] 
ALPHA_B_EXP_UPPER = simulation_design_para['ALPHA_B_EXP_UPPER']
ALPHA_B_NUMBER_POINTS = simulation_design_para['ALPHA_B_NUMBER_POINTS'] 
# alpha_p: Lower and upper limits, step size 
ALPHA_P_LOWER = simulation_design_para['ALPHA_P_LOWER'] 
ALPHA_P_UPPER = simulation_design_para['ALPHA_P_UPPER'] 
ALPHA_P_STEP = simulation_design_para['ALPHA_P_STEP'] 
#
## Load the data for checking, Read from file
data_cheking_file = open('set'+ str(data_set_to_use) + '_check.pickle', 'rb')
data_checking = pickle.load(data_cheking_file) 
data_cheking_file.close()
# END - DO NOT CHANGE

## Task 2A: Caclulating the design objective and constraints for many pairs
# of (alphaB,alphaP) 
# Time vector
# Create a list of regularly spaced time instants
# [0,0.25,0.5,0.75,...,20] 
# 
time_array = np.arange(TIME_START, TIME_END+TIME_DELTA/2, TIME_DELTA)

num_time_points = len(time_array)

# Parameter vectors for design 
# The vector vecAlphaB has been defined for you 
alpha_b_array = np.logspace(ALPHA_B_EXP_LOWER, ALPHA_B_EXP_UPPER, num=ALPHA_B_NUMBER_POINTS) 
#

alpha_b_array, alpha_p_array, max_internal_biofuel, oscillation_internal_biofuel, final_external_biofuel = \
 gn.generate(data_set_to_use, time_array, INITIAL_BACTERIA_AMOUNT, 
 alpha_b_array, ALPHA_P_LOWER, ALPHA_P_UPPER, ALPHA_P_STEP)


#
# Code to check your answers below .. 
#
diffmax_max_internal_biofuel = np.amax(abs(np.subtract(max_internal_biofuel, data_checking['max_internal_biofuel_check']) )) 
diffmax_max_oscillation_internal_biofuel = np.amax(abs(np.subtract(oscillation_internal_biofuel , data_checking['oscillation_internal_biofuel_check']) ))
diffmax_max_final_external_biofuel = np.amax(abs(np.subtract(final_external_biofuel , data_checking['final_external_biofuel_check'])) )


print('Difference in the maximum amount of internal biofuel = ' + str(diffmax_max_internal_biofuel) )
print('Difference in the maximum amount of oscillation_internal_biofuel = ' + str(diffmax_max_oscillation_internal_biofuel) )
print('Difference in the maximum amount of final_external_biofuel = ' + str(diffmax_max_final_external_biofuel) )

 

#!/usr/bin/env python3
 # -*- coding: utf-8 -*-

"""
 ENGG1811 Assignment 2
 Purpose: You can use this program to testthe following function from task 2A:
 (1) generate

"""

import numpy as np
 import pickle
 import biofuel_simulation_design_parameter_sets as bsdps
 import design.py as dn
 import generate as gn

# Use the variable dataSetToUse to choose which parameter set you
 # want to use
 data_set_to_use = 1 # Either 1 or 2
 #

# PLEASE DO NOT CHANGE THIS SECTION
 # BEGIN - DO NOT CHANGE

# The following line reads in the simulation parameters for data_set_to_use,
 # For example: time increment and other parameters you need for simulation
 simulation_design_para = bsdps.biofuel_simulation_design_parameter_sets(data_set_to_use)

# Initial (normalised) amount of bateria
 INITIAL_BACTERIA_AMOUNT = simulation_design_para['INITIAL_BACTERIA_AMOUNT' ]
 # Simulation start and end times, simulation time interval
 TIME_START = simulation_design_para['TIME_START' ] # Start time
 TIME_END = simulation_design_para['TIME_END' ] # End time
 TIME_DELTA = simulation_design_para['TIME_DELTA' ] # Delta t
 # alpha_b: Lower and upper limits, number of points
 ALPHA_B_EXP_LOWER = simulation_design_para['ALPHA_B_EXP_LOWER']
 ALPHA_B_EXP_UPPER = simulation_design_para['ALPHA_B_EXP_UPPER']
 ALPHA_B_NUMBER_POINTS = simulation_design_para['ALPHA_B_NUMBER_POINTS']
 # alpha_p: Lower and upper limits, step size
 ALPHA_P_LOWER = simulation_design_para['ALPHA_P_LOWER']
 ALPHA_P_UPPER = simulation_design_para['ALPHA_P_UPPER']
 ALPHA_P_STEP = simulation_design_para['ALPHA_P_STEP']
 #
 # Design parameters for biofuel system
 # Upper limit on the amount of internal fuel
 THRESHOLD_MAX_INTERNAL_FUEL = simulation_design_para['THRESHOLD_MAX_INTERNAL_FUEL']
 # Upper limit on the amount of oscillation
 THRESHOLD_MAX_OSCILLATION_INTERNAL_FUEL = simulation_design_para['THRESHOLD_MAX_OSCILLATION_INTERNAL_FUEL']
 #

## Load the data for checking, Read from file
 data_cheking_file = open('set'+ str(data_set_to_use) + '_check.pickle', 'rb')
 data_checking = pickle.load(data_cheking_file)
 data_cheking_file.close()

# END - DO NOT CHANGE

time_array = np.arange(TIME_START, TIME_END+TIME_DELTA/2, TIME_DELTA)
 num_time_points = len(time_array)
 # Parameter vectors for design
 # The vector vecAlphaB has been defined for you
 alpha_b_array = np.logspace(ALPHA_B_EXP_LOWER, ALPHA_B_EXP_UPPER, num=ALPHA_B_NUMBER_POINTS)

## Task 2B: Caclulating the design objective and constraints for many pairs
 #
 #

alpha_b, alpha_p, max_internal_biofuel, oscillation_internal_biofuel, final_external_biofuel = \
 gn.generate(data_set_to_use, time_array, INITIAL_BACTERIA_AMOUNT, alpha_b_array, ALPHA_P_LOWER, ALPHA_P_UPPER, ALPHA_P_STEP)

best_alpha_b, best_alpha_p, poor_alpha_b, poor_alpha_p = \
 dn.design( THRESHOLD_MAX_INTERNAL_FUEL, THRESHOLD_MAX_OSCILLATION_INTERNAL_FUEL,
 alpha_b, alpha_p,
 max_internal_biofuel, oscillation_internal_biofuel, final_external_biofuel)

#
 # Print your answers, and manually check them against the expected answers,
 # available from the link provided in the specs (see below).
 # Answers for this part are at, https://www.cse.unsw.edu.au/~en1811/18s1/assigns/ass2/answers.html
 # You need to manually compare/check these answers.

 

 

Find the Answer Or Choose the Processor

———-问答区———————————————————

答疑一:

提问者:

老师您好,请问可以帮我看看这个问题吗?

 

答主:

你好,可以的,请说。

 

答疑二:

提问者:老师,可以帮我下吗?

答主:你好,请说。

提问者:
我没看懂这个最后一行的意思。为什么最后一行是 -1?

答主:

-1 是取array的最后一个数

提问者:

那一行代码可以解释下吗?

答主:

稍等,,,

这句话意思也就是取最后时间的值。

提问者:我看看,这里明白了,

另外一个问题,这一步怎么写的呀,好像没懂。

答主:

就是这句。

答疑三:

提问者:

你好,有时间给我看一下这个问题吗?我不知道哪里出错了,,,,

 

答主:

可以的,你发来看看。

 

 

 

答疑四:

提问者:

在吗?、可以帮下忙吗?

 

答主:

选第四个

 

答疑四:

提问者:

您好老师,可以帮我看看吗?急

 

答主:

选第四个

 

答疑五

提问者:

 

答主:

选第二个

 

答疑六:

提问者:

为什么可以用一个参数接受返回五个参数的函数

答主:

函数返回五个参数,其实是返回一个五个参数的list,可以像如图的方式进行获取,避免了多余参数的定义

 

答疑七:

提问者:

关于np.where函数三个参数模式下怎么用?

 

答主:

如图所示,可以用作类似 a = 0 if condition else 1这样的三元批量替换,可以节省很多代码,且可以替换掉很多循环操作

 

答疑八:

提问者:

你好,ass 2 里2A这里我有点不明白

答主:

这个问题的意思是:创建矩阵alpha_p_array。矩阵最小值是ALPHA_P_LOWER, 最大值是ALPHA_P_UPPER,步长是 ALPHA_P_STEP

提问者:

哦~明白了,谢谢。

 

答疑九:

提问者:

你好,请问output的这三个array,究竟是怎么跟alpha_b_array和alpha_p_array相关联的?

 

答主:

计算output的array中的值时,需要用到写的函数,alpha_b_array和alpha_p_array是函数的参数。

 

提问者:

谢谢啦

 

答疑十:

请问2A 的这三部应该要怎么写?还是不太明白要怎么把1A和1B里的数据带进去。

答主:

通过使用1A和1 B中的函数得到结果 再把结果错放到这三个矩阵中。

答疑十一:

提问者:
if 与else是在同一行,但是平时都是分开,有区别吗?当改动了的时候,没有任何code的改变,但是却运行不了,求原因

答主:

a+=1意思是a=a+1

这个是简写。

 

提问者:

谢谢。

 

答疑十二:

 

KOL提醒:提交的是四份文件。

 

 

 

答疑十三:

提问者:

自己检查不出到底哪里不对?

 

答主:

第14行,定义矩阵长度不对

 

提问者:

可以了谢谢。

 

 

 

我也有疑问

 

 

评论 (3)

  • edd| 五月 23, 2018

    what is wrong with q4 this part:
    sensor_array[x] = sensor_array[x-1] + (ALPHA_R + K_R * I/(I+GAMMA_I) – BETA_R * sensor_array[x-1] * dt)

  • 发表评论

    %d 博主赞过: