Using Python write a genetic algorithm code to solve this strange bank problem.  Suppose, you are the owner of a bank that operates in a strange way. Customers can lend money from your bank (just like a normal bank) and they can also deposit money in your bank. A register is maintained to track the daily transactions. However, being the strange owner of a strange bank, you have a fascination with finding out whether a portion of your daily transactions (in/out) balance out to zero. For example, 1 Lend 100 2 Deposit 150 3 Lend 400 4 Lend 500 5 Deposit 1000 6 Lend 460 7 Deposit 160 8 Deposit 200 9 Lend 500 10 Deposit 100 In this case, there is a portion of the transactions that would balance itself out. (6th, 7th, 8th, and 10th transactions would amount to 0). Task Breakdown: Model the transaction register in a way suitable for the problem. Write a fitness function. Hint: It is the sum of the non-zero elements of a register.  Write the crossover function. Write the mutation function.  Create a population of randomly generated registers. Run genetic algorithms on the population until highest fitness has been reached and/or number of maximum iterations has been reached.  Input The first line has a number N denoting the number of daily transactions followed by N lines each starting with either l or d and a number S denoting the amount of transaction. Here: N ( 1 <=N<= 10^2 ) S ( 1 <=S<= 10^5 ) Output

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Using Python write a genetic algorithm code to solve this strange bank problem. 

Suppose, you are the owner of a bank that operates in a strange way. Customers can lend money from your bank (just like a normal bank) and they can also deposit money in your bank. A register is maintained to track the daily transactions. However, being the strange owner of a strange bank, you have a fascination with finding out whether a portion of your daily transactions (in/out) balance out to zero. For example,

1

Lend

100

2

Deposit

150

3

Lend

400

4

Lend

500

5

Deposit

1000

6

Lend

460

7

Deposit

160

8

Deposit

200

9

Lend

500

10

Deposit

100

In this case, there is a portion of the transactions that would balance itself out. (6th, 7th, 8th, and 10th transactions would amount to 0).

Task Breakdown:

  1. Model the transaction register in a way suitable for the problem.
  2. Write a fitness function. Hint: It is the sum of the non-zero elements of a register. 
  3. Write the crossover function.
  4. Write the mutation function. 
  5. Create a population of randomly generated registers.
  6. Run genetic algorithms on the population until highest fitness has been reached and/or number of maximum iterations has been reached. 

Input

The first line has a number N denoting the number of daily transactions followed by N lines each starting with either l or d and a number S denoting the amount of transaction. Here:

N ( 1 <=N<= 10^2 )

S ( 1 <=S<= 10^5 )

Output

The output would be a binary string denoting the specific transactions that balance themselves to zero or -1 if such a string cannot be formed. String consisting of all zeros won’t be accepted.

 

Example:
Sample Input 1
7
| 120
| 289
d 475
I 195
d 6482
I 160
d 935
Sample Output 1
1011010
Transcribed Image Text:Example: Sample Input 1 7 | 120 | 289 d 475 I 195 d 6482 I 160 d 935 Sample Output 1 1011010
Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Fibonacci algorithm
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education