

# defining a sparce matrix for pokemon i.e mask with 0 & 1s which will be later populated # define model name and objective end goal - max/minīest_team = LpProblem("optimal_team", LpMaximize) With this, we can now proceed to our final code. I have only included those that we will be using. IpSum – function to create a linear expression can be used as constraint or variable later on #expression of form var1*var2+cĮxp = lpSum() #returns : įor more info on the library, refer to the original documentation. LpVariable – Class to Store added variables – Add Variables # adding variable # start, end : 1,5 i.e 1<=var<=5 P = LpProblem("name",objective) # LpMaximize/LpMinimize LpProblem – Base Class for Linear Problem – Problem Initialization # start a linear problem Plup library utilizes classes and their associated functions to carry out the optimization. which makes it easy to work with and is ideal for our use case: Usage of PuLp Library Also, it has a wide variety of integration to create LP files, such as GNU Language Programming Kit (GLPK), CBC, CPLEX, etc. It is very intuitive and user-friendly due to its syntax.

Plup is a python library for construction solving optimization problems as us Linear Programing. So let’s do that! Understanding PuLP Library Now that w e have Aij(sparse matrix) & all the required values stored as a list, it is time to use PuLp library to solve our optimization problem. The different variable represents the equation, e.g staterName – S in eq The Final Piece – Using the PuLp Library
Pokemon team builder code#
The above code is self-explanatory and requires a bit of intermediate python knowledge. # using names to find the index of pokemon and adding mythical index # creating mythyical indices list to later include the constraints StarterNames = ['Turtwig', 'Grotle', 'Torterra', # Equals 1 if the Pokemon is strong against the type indicated 0 otherwiseĪdvantage = ] for i in range(206)] # Accounting for any secondary typings, and adding onto any advantages conferredĮffective_type = list(np.add(strengths,įor s in list(gym_elite_four.loc)])) # Check what types the Pokemon is strong againstĮffective_type.append()]) # iterating through entire data to store different variablesįor row in gen4_dex.itertuples(index=True, name='Pandas'): Total_stats = # total stats/ total column of pokemon datasetĮffective_type = # store pokemon type which are effective agaist the opponents pokemon Names = # list containg all the pokemon names Gen4_dex = gen4_dex.rename(columns= ) # creating list

# changing Types 1 to Type to insure no error Note: S is M -> Image By Author Creating Binary Matrix A ijĪccording to the equation, we must store all the variable values achieved by iterating through all the required columns. Import pandas as pd team_df = pd.read_csv("Datasets/pokemon.csv") We start by loading the CSV file using pandas and printing a few results: import numpy as np
Pokemon team builder download#
It will be great to download both datasets(pokemon.csv & Pokemon Type Chart.csv), save them in a separate folder(datasets), and follow along. Type_chart: For type matchups and effects. Pokemon dataset from Kaggle: For pokemon names and stats. Datasetįor the Problem in hand, we will be using two datasets: Once entered, they are required to defeat four powerful trainers and the champion(uses a variety of different pokemon types)įinally, this clarifies our goal: Can we create a helpful team in fighting these 12 trainers and probably the last one?. Having chosen, they embark on a journey to defeat eight gym leaders, specializing in a specific type, to enter a Pokemon league tournament.ģ. One starts as a lead character who can choose their first pokemon called stater pokemon out of 3.Ģ. The game mechanics also allow for powerful pokemon(legendaries) caught at the end of the game and give upper advantages to the yielder.ġ. Evolution allows an increase in overall strengths, changes in forms, and even provides additional typings.ģ. They can also undergo a genetic transformation two times called evolution. Each one has its primary Type and weakness or advantage over the others. Pokemon are animal-like creatures that are obtainable by battling them. This section is optional and contains a summary of game mechanics in a few points:ġ. Here is a quick summary of the gameplay, which will be helpful later on. This article is a walkthrough to perform just that using PuLp, the linear programming and optimization library. What if I say one can do this by having some knowledge of python, data science, and python. I am sure you must have played pokemon games at some point in time and must have hated the issue of creating an optimal and balanced team to gain an advantage. This article was published as a part of the Data Science Blogathon Introduction
