Page
1
(This page has no text content)
Page
2
MEAP Edition Manning Early Access Program Applied Reinforcement Learning Business optimization and LLM ine-tuning Version 3 Copyright 2026 Manning Publications For more information on this and other Manning titles go to manning.com. © Manning Publications Co. To comment go to liveBook
Page
3
welcome Thank you for purchasing the MEAP for Applied Reinforcement Learning. I’m excited to have you on this journey to explore how we can use one of the most powerful areas of AI to solve meaningful, real-world challenges. To get the most from this book, you should have a basic knowledge of Python programming. While not strictly required, a general understanding of machine learning concepts will be beneficial. I decided to write this book because I saw a major gap in the available resources on Reinforcement Learning. Most books focus on theory or use examples from the world of games, which can feel abstract. This book takes a different approach. We use practical problems inspired by business—like optimizing supply chains or setting prices—to make the core ideas of RL intuitive and easy to grasp. And while we use business optimization as our theme, this book is for anyone seeking a practical, hands-on path to mastering Reinforcement Learning. The challenges of resource allocation, scheduling, and dynamic response are universal in software and data science. By grounding the concepts in tangible examples, you'll gain a deep, intuitive understanding of RL that you can apply anywhere, far beyond the specific case studies in the book. You'll learn how to frame a problem, design a custom environment to simulate it, and apply a range of powerful RL algorithms to find optimal solutions. Your feedback during this MEAP process is invaluable. It will help me create the clearest, most practical, and most effective book possible. Please be sure to post any questions, comments, or suggestions you have in the liveBook discussion forum. Thanks again for your interest and for joining the MEAP! —Hadi Aghazadeh © Manning Publications Co. To comment go to liveBook
Page
4
brief contents PART 1: FUNDAMENTALS: BUILDING A REINFORCEMENT LEARNING TOOLKIT 1 Real-world Decision Making with Reinforcement Learning 2 Markov Decision Process: Turning Problems intro Solvable Models 3 Design Custom Environments for Reinforcement Learning Algorithms PART 2: REINFORCEMENT LEARNING FOR BUSINESS OPTIMIZATION 4 Perfect Knowledge, Optimal Policy: Dynamic Programming 5 Contextual Bandit: Optimizing Stochastic One-step Decisions 6 Tabular Reinforcement Learning 7 Monte Carlo Tree Search: Searching with Reinforcement Learning Principles PART 3: DEEP REINFORCEMENT LEARNING FOR BUSINESS OPTIMIZATION 8 Deep Q-Networks for High-dimensional Data 9 The Calculus of Decisions: Policy Gradient Methods PART 4: REINFORCEMENT LEARNING FOR LARGE LANGUAGE MODELS FINE TUNING 10 Fine-Tuning Large Language Models with PPO 11 Reinforcement Learning with Human Feedback Using GRPO 12 RLVR and Advanced PPO Methods for LLM Reasoning © Manning Publications Co. To comment go to liveBook
Page
5
1 Real-world Decision Making with Reinforcement Learning This chapter covers What is reinforcement learning for business optimization? What are business optimization problems? Challenges in business optimization problems and limitations in the classical solutions How reinforcement learning can help to overcome solution limitations God, grant me the serenity to accept the things I cannot change, courage to change the things I can, and wisdom to know the difference Reinhold Niebuhr, Reformed theologian Even the most powerful businesses have limited resources. In this way, the simple yet important wisdom of a good manager is to understand the strengths and weaknesses of what a business can control, as well as to recognize the opportunities and threats in the environment that surrounds it. And just like the creatures that have lasted millions of years through evolution—not by being the strongest, but by being the most adaptable—a key for a business to survive the brutal competition filled with uncertainties is how well it understands those uncertainties and acts accordingly, based on the limited resources it has. 1 © Manning Publications Co. To comment go to liveBook
Page
6
Making decisions when things are uncertain is probably the most important thing a business has to do—again and again, every single day. And the quality of those decisions depends not just on understanding what’s happening right now, but also on remembering how we got here. Today’s situation isn’t just shaped by today’s problems—it’s also the result of yesterday’s choices. If a business can make the right decisions—right enough, given what it knows and the resources it has—it can not only stay in the game, but actually earn the right to keep playing. Because in a world full of moving parts, good decision- making isn’t just a one-time win—it’s a habit that pays off over time. As a result, making sequential decisions under uncertainty is something every business should aim for. You might get the impression from this next sentence that the author is in love with what he does, and that the only tool he has is a hammer—so everything looks like a nail to him, and he wants to prescribe a single solution for all the complexities of business —but I must admit that making sequential decisions under uncertainty is exactly what reinforcement learning does. Let’s get the picture first. 1.1 What reinforcement learning really enables? Before we talk about business, let’s talk about war. Not actual war—StarCraft II. In 2019, DeepMind’s AlphaStar quietly climbed the ranks of professional players in this wildly complex real-time strategy game. For those unfamiliar, StarCraft isn’t your average board game—it’s chaotic, dynamic, and multi-agent. You’re managing resources, building infrastructure, countering your opponents, all while being bombarded with incomplete information. In other words, it’s a perfect metaphor for running a real business in a competitive market. But what’s fascinating isn’t the game—it’s how AlphaStar learned to play it. It wasn’t taught rules in the traditional sense. It wasn’t trained on a labeled dataset. It didn’t memorize expert strategies. Instead, it learned by doing. It played millions of matches against itself, continuously trying new things, making mistakes, observing the outcomes, and gradually refining its strategies—not unlike how a startup iterates to find product- market fit. This is reinforcement learning in action: an agent learns how to act in an environment by trying, failing, adjusting, and trying again. Over time, the agent doesn’t just copy what worked before—it develops policies for making good decisions, even in new and unseen situations. If we think about what makes reinforcement learning unique compared to other types of machine learning, a visual like the one below becomes quite helpful. Let’s walk through figure 1.1 illustration to clarify where reinforcement learning fits in and how it stands apart. 2 © Manning Publications Co. To comment go to liveBook
Page
7
Figure 1.1 Reinforcement learning in the context of machine learning. Unsupervised Learning is like walking into a room full of people and trying to figure out who belongs to which group, without anyone telling you what those groups are. The task here is to extract patterns from raw data—clustering customers by behavior, for example—but there's no reward or correct answer to guide you. Supervised Learning, on the other hand, gives you a cheat sheet. It says, “Here are a bunch of past situations, and here’s what the correct outcome was.” The model's job is to learn the mapping between inputs and outputs—like predicting whether a customer will churn or whether a transaction is fraudulent. It learns from labeled data and is evaluated based on how well it predicts unseen cases. Reinforcement Learning, as depicted in the third panel is about learning how to act, not just predict. The agent makes decisions (like moving from one node to another), receives rewards or penalties based on the outcome, and learns from these consequences. The key challenge is credit assignment—figuring out which of the past decisions led to success or failure. In reinforcement learning panel, the agent chooses different paths and gets different amounts of reward (100, 200, 30, 50), but it doesn't know in advance which path is best. It must explore, experiment, and learn what leads to higher cumulative outcomes. And that "How?" at the bottom? That’s the heart of reinforcement learning: how to act to maximize long-term value. 3 © Manning Publications Co. To comment go to liveBook
Page
8
This distinction is crucial for what follows in this book. Supervised learning might tell you which product a customer is likely to buy. But reinforcement learning can learn how to sequence a series of actions—like promotions, inventory allocation, or truck dispatching—to maximize sales, reduce cost, or improve customer satisfaction over time. In that sense, running a business is much more like playing StarCraft than it is like identifying cats in photos. And that’s exactly what this book is about: how to take the core concepts behind reinforcement learning and apply them to real-world business optimization problems. But before we dive in, we’ll first look at the types of questions businesses need to answer, the structure of business problems, and the kinds of decisions that matter most. 1.2 Different types of business analysis As a small dose of reality, although all problems that reinforcement learning tries to solve can be framed as sequential decision-making under uncertainty, not all sequential decision- making problems can be solved using reinforcement learning. So, when it comes to helping businesses with analytical tools, we need to understand what kinds of questions we are asking, and which tools are capable of answering what. We can broadly divide the variables and complexities that businesses face into two main categories: external and internal factors. External factors are those beyond the business’s control—shaped by macroeconomic trends, social dynamics, the moves of competitors, and shifts in customer behavior. These are the unpredictable forces that come from the outside world. In contrast, internal factors refer to elements a business can control, either fully or to some extent. These include decisions related to hiring, marketing strategies, pricing, operational planning, and overall organizational efficiency. Understanding how these internal and external forces interact is key to navigating uncertainty and making informed decisions. With this division, we can also divide the types of questions we ask. Let’s first deal with external factors. Figure 1.2 provides an overview of the types of questions related to external factors. Just like any other system, a business can be understood across three time frames: past, present, and future. 4 © Manning Publications Co. To comment go to liveBook
Page
9
Figure 1.2 two types of questions and analytical approaches for analyzing external factors. From our current point in time, if we are interested in analyzing the past, the question we ask is “What happened?” This type of analysis is called Descriptive Analysis. For example, if you ask, “What has been the inflation trend over the last ten years?”, you’re asking a descriptive question. On the other hand, if we’re interested in the future status of external factors—based on the implicit assumption that future trends will resemble past patterns—the question we ask becomes “What will happen?” This type of analysis is known as Prediction or Forecasting. For instance, asking “How much will raw material prices be in the next quarter?” is a prediction-type question. Now let’s move to analyzing internal factors, which a business has control over—either fully or at least partially. We can look at them using the same lens we used for external factors, as shown in figure 1.3. 5 © Manning Publications Co. To comment go to liveBook
Page
10
Figure 1.3 two types of questions and analytical approaches for analyzing internal factors. Again, from our current position, if we are looking into the past of internal factors, the question becomes “Why did it happen?” and the corresponding analysis is called Explanatory Analysis. The “why” matters here because the business itself has been a major part of what happened. For example, asking “Why did sales shrink by 20% compared to last quarter?” is an explanatory question. Last but not least, if you’re interested in the future of internal factors—and since you have some control over them—you might ask, “What should we do?”. Here, you’re aiming to optimize your part in shaping the future of that internal variable that we call Optimization. For example, if you ask “What is the best schedule for dispatching 20 trucks to cover all customer orders while minimizing costs?”, you’re asking an optimization-type question. Table 1.1 summarize these key definitions which are central in machine learning. Table 1.1 Summary of business analysis types. Factor Type Time Frame Key Question Type of Analysis Example External Past What happened? Descriptive Analysis What has been the inflation trend over the last ten years? External Future What will happen? Predictive Analysis How much will raw material prices be in the next quarter? Internal Past Why did it happen? Explanatory Analysis Why did sales shrink by 20% compared to last quarter? Internal Future What should we do? Optimization Analysis What is the best schedule for dispatching 20 trucks to minimize costs? 6 © Manning Publications Co. To comment go to liveBook
Page
11
There are a few important points to mention here: since internal factors can also be influenced by external ones—in other words, a business might not have full control over a variable but still have partial control—it can still be considered an internal factor. What matters is having some level of control, which allows you to ask internal-type questions. Because of this partiality in internal factors, you may—and often should—ask external-type questions for internal factors too. This is why, in almost all types of business analysis approaches, the first step is usually to start with descriptive analysis, and then study how much of the current situation is shaped by external factors. Although this division between external and internal may be controversial—especially in edge cases—based on the idea that “all models are wrong, but some are useful”, our purpose here is to distinguish between different analytical frameworks as clearly as possible, so we can understand which approach should be used and when. Although asking the right questions is a critical step in solving a problem, the way we answer each of these questions can also significantly impact the outcomes in reality. One may ask a priest for insights on the next moves of their competitors, or they may use game theory to model the dynamics of value exchange in a marketplace. In the end, it is the decision maker’s mindset—or mental model—that determines the chosen approach to solving the problem. As for the focus of this book, we are primarily interested in understanding and optimizing the future status of a business. To analyze and influence that future, two main solution approaches are commonly used: Model-based and Data-driven methods. Model- based approaches rely on carefully designed assumptions, parameters, and expert knowledge to construct a representation of how the problem is believed to work. In contrast, data-driven approaches learn directly from historical data, identifying patterns and relationships that can then be applied to predict or guide future outcomes in unseen scenarios. These approaches automatically learn the model from the data itself, without the need for manually specifying rules or assumptions. Both approaches have their strengths, and in many cases, a hybrid of the two offers the most practical results. Depending on the type of factor—internal or external—we might choose different approaches. However, the main focus of this book is business optimization, and in particular, how reinforcement learning can help in solving business optimization problems. But before we dive into that, we need to go a bit deeper into what business optimization actually means. 1.3 Business optimization definition When it comes to business optimization, we should first talk about when we should do business optimization, and this usually falls into four main aspects: Decision Level: Whether the decision is strategic, tactical, or operational. Decision Cycle: Whether the decision is periodic, one-time, or occasional. 7 © Manning Publications Co. To comment go to liveBook
Page
12
Decision Dimensions: Whether a decision is going to be made for single entity or multiple entities. Decision Quantifiability: Whether the decision can be quantified and measured (even in binary form) or whether it is more qualitative and based on intuition. From the different combinations that can be made using these categories, business optimization usually (but not always) applies to problems that are at the operational level, occur periodically, involve many decisions, and can be quantified in some way. Needless to say, as we move toward the strategic level, the number of decisions and their frequency decrease, while their nature becomes more qualitative. In those cases, the “optimal” answer is more subjective and depends heavily on the preferences and opinions of managers. For these other combinations, there are plenty of alternative approaches— conceptual models in strategic management like Michael Porter’s Five Forces, McKinsey’s 7S Framework, Blue Ocean Strategy, and other tactical-level models such as those for designing supply chain networks. Now that we’ve drawn a rough boundary around the types of problems we want to solve, it’s time to look at what characteristics a typical business problem usually has. Figure 1.4 shows a framework for this purpose. Figure 1.4 Framework for business optimization models. 8 © Manning Publications Co. To comment go to liveBook
Page
13
According to figure 1.4, any business optimization model should include these key elements in its framework. First, it should take two types of inputs. The first is external factors, which are usually passed into the model as parameters. For example, if the model is for managing a stock portfolio, one external factor could be the price of raw materials, which can be provided based on descriptive analysis or relevant historical data. Once the model is solved, we can run sensitivity analysis on these parameters to see how changes in their values affect the objective function. The second—and most important—input is actions, or decision variables. These are the things we want to make decisions about. Questions like “How much money should a company invest in a product?” or “What should the product price be?” fall into this category and represent the core of the decision-making process. Once the inputs are set, the next step is to define the structure of the problem. Every business optimization model should include a framework to define the objective(s)—what we want to optimize, either by minimizing or maximizing, depending on the nature of the problem. The objective function could be a single one, such as minimizing total cost or makespan —the total time required to complete all tasks from start to finish— but in more realistic scenarios, there are often multiple objectives—like minimizing cost while also balancing workload, maximizing efficiency while maintaining customer satisfaction, and so on. But perhaps the most important aspect of any business optimization model is the constraints. This is what makes life difficult—for both the modeler and the model itself. Businesses are surrounded by all kinds of limitations: physical constraints, regulatory requirements, customer expectations, employee satisfaction, environmental considerations, and more. The way a framework or model handles these constraints—balancing realism while keeping things simple enough to be solvable—determines how powerful and useful that model really is. We’ll be talking a lot more about constraints in the upcoming chapters, so stay tuned. Once the inputs, objective function, and constraints are defined, the model can be run, and it should give at least two types of outputs. Metrics, to show the value of the objective function and values for each decision variable, showing what actions should be taken. For instance, once a vehicle routing problem is solved, the model should tell us the total distance traveled (if that’s the only objective), and it should also tell us which vehicle should visit which location—and in what order. We will return to this framework when we discuss how reinforcement learning can help us (and yes, I know how impatient you are to finally see reinforcement learning show up!). Please bear with me for a few more pages as we look at some real-world examples of business optimization problems. This will help us better understand the challenges involved and give us a clearer idea of when and how reinforcement learning can be useful. 9 © Manning Publications Co. To comment go to liveBook
Page
14
1.4 Examples of business optimization problems Now that we’ve drawn a rough boundary around the kinds of decisions business optimization is best suited for—typically operational, recurring, involving multiple entities, and quantifiable to some extent—let’s walk through some real-world examples. These are the types of problems where a formal optimization framework can shine. They’re not just abstract concepts—they’re common in many industries with different details but similar structure and form the backbone of day-to-day operational decision-making. a. Inventory Replenishment in Retail Chains: Retailers deal with hundreds or thousands of products across dozens (or even hundreds) of locations. Figuring out how much to reorder, and when, is a classic business optimization problem. The external inputs here are demand forecasts and supplier lead times, and the decision variables are order quantities per product per store. The objective is usually to minimize total cost—including ordering, holding, and stockout costs—while satisfying service level requirements. A service level agreement (SLA) defines the desired availability of products—typically as the percentage of demand that should be fulfilled immediately without backorders—and contributes to the objective function by acting as a constraint that balances customer satisfaction against cost efficiency. This problem is inherently operational, happens periodically (daily, weekly, or monthly), spans multiple entities (products, stores), and is highly quantifiable. b. Vehicle Routing for Delivery Fleets: Any business that delivers goods —whether it’s groceries, parcels, or construction materials—faces the question: which vehicle should go where, and in what order? External factors like customer locations and traffic patterns feed into the model, while the decisions involve sequencing visits across a fleet. The objective might be minimizing total distance, delivery time, or fuel consumption. This problem repeats frequently (often daily), involves many vehicles and customers, and can be clearly measured—making it a textbook case for optimization. c. Production Scheduling in Manufacturing: Factories are constantly making decisions about what to produce, when to produce it, and in what quantity. These decisions are driven by order demand, machine availability, and production rates. The goal might be to minimize production and inventory costs or maximize throughput. The decision variables are production quantities or job sequences on machines. In many real-world scenarios, the number of production tasks exceeds the available machine capacity, requiring the system to prioritize jobs based on urgency, value, or deadlines—a classic example of managing oversubscribed tasks. This is an operational, recurring problem that deals with multiple production lines or products, and its metrics are usually cost or time-based—again, highly measurable. 10 © Manning Publications Co. To comment go to liveBook
Page
15
d. Workforce Shift Scheduling: In service-heavy industries like healthcare (Nurse rostering), hospitality, or customer support, scheduling staff efficiently is crucial. Here, the model takes into account employee availability, forecasted workload, and legal requirements (like rest time or maximum hours). The decisions revolve around assigning employees to shifts. The objective might be to minimize understaffing, workload balancing or labor cost while ensuring coverage. This problem occurs regularly (weekly or biweekly), affects multiple teams or departments, and has clear constraints and outputs. e. Rebalancing Bike-Sharing Stations: Cities with bike-sharing systems often face the problem of some stations being empty while others are full. Rebalancing bikes between stations is a logistical task done daily. Inputs include real-time demand, current bike counts, and traffic conditions. Decisions involve routing vehicles to pick up or drop off bikes. The objective is usually to minimize total imbalance across the network while reducing routing cost. It’s periodic, multi-entity (vehicles, stations), and can be fully quantified. f. Dynamic Pricing for Perishable Goods: In industries like airlines, hospitality, or food retail, pricing decisions need to be made frequently as inventory perishes or loses value over time. These prices depend on demand forecasts, time until expiration, and competitor pricing. The decision variables are price points at different times. The objective is revenue maximization. Although strategic pricing can be qualitative, operational-level dynamic pricing—like daily markdowns in grocery stores —is periodic, affects multiple products, and is measurable in terms of sales and profit. These examples aren’t just theoretical—they’re the kinds of problems businesses deal with every single day. What makes them a good fit for business optimization is that they’re systematic, repeated, and data-driven. They’re also complex enough to benefit from automation, yet structured enough to be modeled using math. That’s the sweet spot where business optimization lives. We could easily keep expanding this list, but that’s not the point here. The goal was just to dip our toe in the water before diving in headfirst—because jumping in without first appreciating how tricky and resource-consuming these problems can be to model and solve is a great way to waste effort, energy, and perhaps the most precious resource of all: time. After all, we’re talking about optimization—so it only makes sense to optimize how we approach the reading and writing journey ahead too. 11 © Manning Publications Co. To comment go to liveBook
Page
16
1.5 Challenges in business optimization problems What do you think makes a product feel like a “high-quality” one? The answer can be controversial and often depends on personal perspective. But if we refer to Edwards Deming—one of the pioneers of the quality improvement movement in Japan and the USA during the late 1980s—he famously said that a product is the outcome of a process. That means the product you hold in your hand might be great, while the same product in mine could be disappointing. As a result the process of producing that product matters not the product itself. This brings us to a very important concept—one that applies not only to business operations but also to how we build models in machine learning and business optimization. According to Dr.Deming and others in his field, a process is considered high-quality when it has low variance and low bias. In other words, a good process is one that can consistently do the right things, the right way, most of the time. This concept is illustrated in figure 1.5. Figure 1.5 Variance and bias trade off in business optimization models. According to figure 1.5, the quality of a model—or any process—should be evaluated across time, meaning we have to test it in a variety of different situations. Variance refers to how scattered or inconsistent the results are across those situations. Bias, on the other hand, is about how far the results are from the actual goal or target. 12 © Manning Publications Co. To comment go to liveBook
Page
17
Now, back in the world of business optimization, the ultimate goal for any model is to keep both variance and bias as low as possible. But here’s the catch: these two aren’t independent. In fact, as they call it “there is no free lunch”, we usually have to make a trade-off between them. Reducing one often increases the other, and finding the right balance is where things get tricky. Both variance and bias come with their own set of metrics and performance indicators, each telling us something about the model from a different angle. At the end of the day, it’s up to the business—and more specifically, the managers—to decide how to handle this ongoing trade-off. As a matter of fact, in table 1.2, we’ll walk through some of the most common criteria that can help us better understand the challenges business optimization models can face. 13 © Manning Publications Co. To comment go to liveBook
Page
18
Table 1.2 Practical evaluation criteria for business optimization models. Dimension Definition Why it matters Risk if ignored Robustness Handles noisy or imperfect inputs without breaking. Keeps the model reliable in messy, real-world conditions. Model collapses when small assumptions change. Resilience Can recover and keep working after a disruption Business environments shift—resilient models continue delivering value. Model fails entirely after a shock or error. Real-time Respons Produces decisions quickly enough to act on them. Many business contexts (e.g., pricing, routing) require fast actions. Slow responses make the model irrelevant. Adaptability Learns or adjusts as conditions change. Maintains effectiveness over time as customer needs or markets shift. Becomes obsolete when faced with new patterns. Flexibility Can be extended or modified without major rework. Saves time and cost when adding new constraints or features. Requires rebuilding the entire system to make small changes. Generalizability Works well across different use cases or teams. Avoids reinventing the wheel for every new scenario. Performs well only in one narrow use case. Customizability Easily adjusted to meet specific stakeholder needs. Different teams need different reports, KPIs, or configurations. Users feel disconnected or underserved by a one-size-fits-all model. Effort to Build Time, data prep, and expertise needed to create the model. High upfront costs can block progress or delay results. Teams underestimate the time and effort required to launch. Effort to Operationalize Difficulty in deploying and using the model in real workflows. Models must fit into systems and be usable by non-technical staff. Great model on paper never makes it into production. 14 © Manning Publications Co. To comment go to liveBook
Page
19
Dimension Definition Why it matters Risk if ignored Lifecycle Cost Total cost of maintaining and updating the model over time. Ongoing retraining, updates, and monitoring can drain resources. Model becomes a burden due to high maintenance costs. Interpretability Outputs and logic are understandable to humans. Increases trust, enables better decision-making, and supports auditing or compliance. Stakeholders won’t trust or adopt a model they don’t understand. These metrics are just a few among many we could discuss. The important thing to keep in mind is that, just like the business world itself—full of constraints and limitations—building a model to solve business problems means we not only have to respect those real-world constraints, but also the ones that come with the modeling approach itself. In the next section, we’ll walk through some of the well-known modeling methods that have been used in practice. 1.6 Classical business optimization models Now that we’ve explored the types of problems business optimization can handle—and some of the challenges we need to watch out for—it’s time to take a closer look at the classical modeling methods. These are the tools that have been around for decades, forming the foundation of most business decision-making systems. Each of them has its own strengths, assumptions, and areas where it performs best. Let’s walk through some of them. 1.6.1 Operations research Operations research is one of the oldest and most widely used tools in business optimization. You can think of operations research as the art and science of turning real- world problems into mathematical ones. At its core, operations research tries to help decision-makers make better choices using models, logic, and mathematical optimization techniques. Operations research problem formulation consists of defining decision variables, an objective function, and a set of constraints that reflect the limitations or rules of the problem. Imagine a bakery that wants to make two types of cakes: chocolate and vanilla. Each chocolate cake needs 2 hours of labor and 3 kg of flour. Each vanilla cake needs 1 hour of labor and 2 kg of flour. The bakery has 100 hours of labor and 150 kg of flour. Each chocolate cake earns $5 and each vanilla cake earns $4. How many of each should they make to maximize profit? To define decisions variables, let 𝑥1 be the number of chocolate cakes and 𝑥2 the vanilla ones, we can represent these sets of constraints and objectives via a mathematical formulation that has been shown in figure 1.6. 15 © Manning Publications Co. To comment go to liveBook
Page
20
Figure 1.6 Linear programming formulation of bakery shop problem. The example above is a probably the simplest yet classical operations research problem formulation called linear programming. And trust me—this same structure shows up in supply chains, finance, scheduling, transportation, and more. Depending on the nature of the problem, we have different types of operations research models: Linear Programming (LP): Objective and constraints are linear. It means the relationship between mathematical variables can all be expressed as straight lines—no curves, no powers, no complex interactions. Mixed Integer Programming (MIP): Some variables must be integers (like number of trucks). The relationships between variables is still linear. Nonlinear Programming (NLP): If either the objective or the constraints are nonlinear. The beauty of operations research is that once you formulate the problem, you can use powerful solvers like Gurobi, CPLEX, or open-source ones that you don’t have to pay to use it like CBC to get the solution. Build on top advanced mathematical foundations—such as linear algebra, combinatorics, and convex optimization, these solvers use smart algorithms, like branch-and-bound, cutting planes, or interior-point methods to find optimal results. 1.6.2 Stochastic simulation Not everything in business is neat and deterministic. Sometimes, randomness plays a big role—and that’s where stochastic simulation becomes a powerful tool. Unlike optimization models that aim to find a single “best” solution, simulation models help us explore how a system behaves under uncertainty. They’re not about giving one final answer but about understanding the range of possibilities and how those possibilities shift when conditions change. 16 © Manning Publications Co. To comment go to liveBook