{"id":41,"date":"2025-12-17T15:15:43","date_gmt":"2025-12-17T15:15:43","guid":{"rendered":"https:\/\/qc.thelazydreamer.com\/?p=41"},"modified":"2025-12-17T15:15:44","modified_gmt":"2025-12-17T15:15:44","slug":"chapter-2-qubo-building-blocks","status":"publish","type":"post","link":"https:\/\/qc.thelazydreamer.com\/?p=41","title":{"rendered":"Chapter 2 &#8211; QUBO Building Blocks"},"content":{"rendered":"\n<p><em>(Binary Variables, Penalties, and Objectives)<\/em><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"535\" src=\"https:\/\/qc.thelazydreamer.com\/wp-content\/uploads\/2025\/12\/edited-image-1765984305391-1024x535.png\" alt=\"\" class=\"wp-image-42\" srcset=\"https:\/\/qc.thelazydreamer.com\/wp-content\/uploads\/2025\/12\/edited-image-1765984305391-1024x535.png 1024w, https:\/\/qc.thelazydreamer.com\/wp-content\/uploads\/2025\/12\/edited-image-1765984305391-300x157.png 300w, https:\/\/qc.thelazydreamer.com\/wp-content\/uploads\/2025\/12\/edited-image-1765984305391-768x401.png 768w, https:\/\/qc.thelazydreamer.com\/wp-content\/uploads\/2025\/12\/edited-image-1765984305391-1140x596.png 1140w, https:\/\/qc.thelazydreamer.com\/wp-content\/uploads\/2025\/12\/edited-image-1765984305391.png 1408w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><strong>Goal of this chapter<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Understand the 3 ingredients of every QUBO<\/li>\n\n\n\n<li>Learn what penalties are and why they work<\/li>\n\n\n\n<li>Practice with simple, real-life examples<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">1. Binary Variables (Yes \/ No switches)<\/h2>\n\n\n\n<p>QUBO only uses <strong>binary variables<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>0<\/code> = NO \/ not chosen \/ not active<\/li>\n\n\n\n<li><code>1<\/code> = YES \/ chosen \/ active<\/li>\n<\/ul>\n\n\n\n<p>Think of them as <strong>on\/off switches<\/strong>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Example: 3 drinks<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>C = 1<\/code> \u2192 choose Coke<\/li>\n\n\n\n<li><code>M = 1<\/code> \u2192 choose Milk Tea<\/li>\n\n\n\n<li><code>O = 1<\/code> \u2192 choose Orange Juice<\/li>\n<\/ul>\n\n\n\n<p>All variables must be:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>C, M, O \u2208 {0,1}\n\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">2. Objective Function (What you want to optimize)<\/h2>\n\n\n\n<p>QUBO always <strong>minimizes<\/strong> a formula.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Smaller value = better<\/li>\n\n\n\n<li>Bigger value = worse<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Example: Drink preference<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Coke is your favorite \u2192 <code>5<\/code><\/li>\n\n\n\n<li>Milk Tea you dislike \u2192 <code>+10<\/code><\/li>\n\n\n\n<li>Orange Juice is neutral \u2192 <code>0<\/code><\/li>\n<\/ul>\n\n\n\n<p>Objective:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-5C + 10M + 0O\n\n<\/code><\/pre>\n\n\n\n<p>Lower score = better choice.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">3. Constraints using Penalties (Rules)<\/h2>\n\n\n\n<p>Real problems have <strong>rules<\/strong>, such as:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Choose exactly 1 item<\/li>\n\n\n\n<li>Do not choose A and B together<\/li>\n\n\n\n<li>Choose at most 2 items<\/li>\n<\/ul>\n\n\n\n<p>QUBO enforces rules using <strong>penalties<\/strong>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">What is a Penalty?<\/h2>\n\n\n\n<p>A <strong>penalty<\/strong> is extra cost added when a rule is broken.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Rule satisfied \u2192 penalty = <code>0<\/code><\/li>\n\n\n\n<li>Rule broken \u2192 penalty = positive number<\/li>\n<\/ul>\n\n\n\n<p>Because QUBO minimizes, it naturally avoids penalties.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Why penalty = 0 or 1 in simple examples?<\/h2>\n\n\n\n<p>Many rules can be written so that:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Valid solution \u2192 penalty = <code>0<\/code><\/li>\n\n\n\n<li>Invalid solution \u2192 penalty = <code>1<\/code><\/li>\n<\/ul>\n\n\n\n<p>Later, we multiply by a <strong>penalty weight<\/strong> to make rules important.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">How to choose penalty weight?<\/h2>\n\n\n\n<p>Simple rule:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Penalty weight should be larger than objective values<\/p>\n<\/blockquote>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Objective range<\/th><th>Safe penalty<\/th><\/tr><\/thead><tbody><tr><td>0 ~ 5<\/td><td>10<\/td><\/tr><tr><td>0 ~ 10<\/td><td>20<\/td><\/tr><tr><td>0 ~ 50<\/td><td>100<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>If penalty is too small \u2192 rules may break<\/p>\n\n\n\n<p>If penalty is large \u2192 always safe<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">4. Super Simple Example: Choose 1 Drink (2 options)<\/h2>\n\n\n\n<p>Variables:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>C \u2208 {0,1}\nP \u2208 {0,1}\n\n<\/code><\/pre>\n\n\n\n<p>Constraint:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>C + P = 1\n\n<\/code><\/pre>\n\n\n\n<p>QUBO penalty form:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>(C + P - 1)\u00b2\n\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Check it<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>C<\/th><th>P<\/th><th>Result<\/th><th>Meaning<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td>0<\/td><td>0<\/td><td>Valid<\/td><\/tr><tr><td>0<\/td><td>1<\/td><td>0<\/td><td>Valid<\/td><\/tr><tr><td>0<\/td><td>0<\/td><td>1<\/td><td>Invalid<\/td><\/tr><tr><td>1<\/td><td>1<\/td><td>1<\/td><td>Invalid<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Valid \u2192 penalty = 0<\/p>\n\n\n\n<p>Invalid \u2192 penalty = 1<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">5. Assessment Problem (3 Drinks)<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Problem<\/h3>\n\n\n\n<p>You have:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Coke<\/li>\n\n\n\n<li>Milk Tea<\/li>\n\n\n\n<li>Orange Juice<\/li>\n<\/ul>\n\n\n\n<p>Choose <strong>exactly 1<\/strong>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Variables<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>C, M, O \u2208 {0,1}\n\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Constraint<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>C + M + O = 1\n\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">QUBO formula<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>(C + M + O - 1)\u00b2\n\n<\/code><\/pre>\n\n\n\n<p>Optional penalty weight <code>P<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>P(C + M + O - 1)\u00b2\n\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">6. Practice (Homework)<\/h2>\n\n\n\n<p>Try writing QUBO for:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Choose <strong>at most 1<\/strong> drink<\/li>\n\n\n\n<li>Choose <strong>at least 1<\/strong> drink<\/li>\n\n\n\n<li>Choose <strong>exactly 2<\/strong> drinks<\/li>\n\n\n\n<li>Add preferences:\n<ul class=\"wp-block-list\">\n<li>Coke = -5<\/li>\n\n\n\n<li>Milk Tea = +7<\/li>\n\n\n\n<li>Orange Juice = 0<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<p>Combine <strong>objective + constraint<\/strong> into one QUBO.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>(Binary Variables, Penalties, and Objectives) Goal of this chapter 1. Binary Variables (Yes \/ No switches) QUBO only uses binary variables: Think of them as on\/off switches. Example: 3 drinks All variables must be: 2. Objective Function (What you want to optimize) QUBO always minimizes a formula. Example: Drink preference Objective: Lower score = better choice. 3. Constraints using Penalties (Rules) Real problems have rules, such as: QUBO enforces rules using penalties. What is a Penalty? A penalty is extra cost added when a rule is broken. Because QUBO minimizes, it naturally avoids penalties. Why penalty = 0 or 1 in simple examples? Many rules can be written so that: Later, we multiply by a penalty weight to make rules important. How to choose penalty weight? Simple rule: Penalty weight should be larger than objective values Objective range Safe penalty 0 ~ 5 10 0 ~ 10 20 0 ~ 50 100 If penalty is too small \u2192 rules may break If penalty is large \u2192 always safe 4. Super Simple Example: Choose 1 Drink (2 options) Variables: Constraint: QUBO penalty form: Check it C P Result Meaning 1 0 0 Valid 0 1 0 Valid 0 0 1 Invalid 1 1 1 Invalid Valid \u2192 penalty = 0 Invalid \u2192 penalty = 1 5. Assessment Problem (3 Drinks) Problem You have: Choose exactly 1. Variables Constraint QUBO formula Optional penalty weight P: 6. Practice (Homework) Try writing QUBO for: Combine objective + constraint into one QUBO.<\/p>\n","protected":false},"author":1,"featured_media":42,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-41","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"jetpack_featured_media_url":"https:\/\/qc.thelazydreamer.com\/wp-content\/uploads\/2025\/12\/edited-image-1765984305391.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/qc.thelazydreamer.com\/index.php?rest_route=\/wp\/v2\/posts\/41","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/qc.thelazydreamer.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qc.thelazydreamer.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qc.thelazydreamer.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/qc.thelazydreamer.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=41"}],"version-history":[{"count":1,"href":"https:\/\/qc.thelazydreamer.com\/index.php?rest_route=\/wp\/v2\/posts\/41\/revisions"}],"predecessor-version":[{"id":43,"href":"https:\/\/qc.thelazydreamer.com\/index.php?rest_route=\/wp\/v2\/posts\/41\/revisions\/43"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/qc.thelazydreamer.com\/index.php?rest_route=\/wp\/v2\/media\/42"}],"wp:attachment":[{"href":"https:\/\/qc.thelazydreamer.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=41"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qc.thelazydreamer.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=41"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qc.thelazydreamer.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=41"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}