<?xml version="1.0" encoding="UTF-8" ?><!-- generator=Zoho Sites --><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><atom:link href="https://www.prescient.consulting/blogs/tag/python/feed" rel="self" type="application/rss+xml"/><title>Prescient Analytics - Blog #Python</title><description>Prescient Analytics - Blog #Python</description><link>https://www.prescient.consulting/blogs/tag/python</link><lastBuildDate>Fri, 12 Sep 2025 06:42:57 -0700</lastBuildDate><generator>http://zoho.com/sites/</generator><item><title><![CDATA[First Look at OR-Tools]]></title><link>https://www.prescient.consulting/blogs/post/First-Look-OR-Tools</link><description><![CDATA[<img align="left" hspace="5" src="https://www.prescient.consulting/files/blog_img/orLogo-1-.png"/>First look at using Google's Open Source OR-Tools library for Constraint Optimsation.]]></description><content:encoded><![CDATA[<div class="zpcontent-container blogpost-container "><div data-element-id="elm_I97l1t8iQ72z75_r7crdyw" data-element-type="section" class="zpsection "><style type="text/css"></style><div class="zpcontainer-fluid zpcontainer"><div data-element-id="elm_5PJA_zveQA6M5sESoehAqg" data-element-type="row" class="zprow zprow-container zpalign-items- zpjustify-content- " data-equal-column=""><style type="text/css"></style><div data-element-id="elm_6Md-l1NRT7eZPKEVJF2Oog" data-element-type="column" class="zpelem-col zpcol-12 zpcol-md-12 zpcol-sm-12 zpalign-self- "><style type="text/css"></style><div data-element-id="elm_H7WQoc21QPK6jvTiH8AKLA" data-element-type="text" class="zpelement zpelem-text "><style></style><div class="zptext zptext-align-center " data-editor="true"><div style="text-align:left;"><div>For a recent project that involved an optimisation problem, I settled on using the OR-Tools library, an open-source project from Google (<a href="https://developers.google.com/optimization" title="https://developers.google.com/optimization" target="_blank">https://developers.google.com/optimization</a>).</div></div><div style="text-align:left;"><div><br></div><div>Of interest to me was its CP-SAT solver which claimed good solution speed based on Constraint Programming (<a href="https://en.wikipedia.org/wiki/Constraint_programming" title="https://en.wikipedia.org/wiki/Constraint_programming" target="_blank">https://en.wikipedia.org/wiki/Constraint_programming</a>)</div></div><p style="text-align:left;"><span style="color:inherit;"><br></span></p><div style="text-align:left;">Key selling points:</div><ol><li style="text-align:left;">Documentation looked good with plenty of examples – this was critical since I was starting from zero and needed to get up to speed quickly;<br></li><li style="text-align:left;">Has a Python interface, which is the only programming language I consider myself a capable developer in;&nbsp;<br></li><li style="text-align:left;">Supports a number of solver back-ends; although I did not get a chance to try this out; and</li><li style="text-align:left;">If Google uses it, it must be good... right?</li></ol><p style="text-align:left;"><br></p><p style="text-align:left;">As someone who has more experience with Stats/Machine Learning models, Constraint Optimisation presented an interesting challenge given the way models need to be defined;&nbsp;<br></p><div style="text-align:left;"><ul><li style="text-align:left;">Variables must be integers, this means multiplying decimal variables to a magnitude that allows the truncation of the decimal component.</li><li>Expression are in the form of linear equations, which creates some limitations. For example you are unable to simply multiply variables within the same expression such as y = a * b, however you can work around this; in this case one has to use a function cp_model.AddProdEquality(, [])</li></ul></div><p style="text-align:left;"><span style="color:inherit;"><br></span></p><div style="text-align:left;">To note however, that the CP-SAT solver although superior, has a different Python API to the previous CP Solver which (on face value) appeared to have more flexibility in how equations could be constructed.</div><p style="text-align:left;"><span style="color:inherit;"><br></span></p><div style="text-align:left;">Also, more generally, when referring to the API docs (which are presented in C++) there appears to be certain things that are either not represented in the Python API, or not well documented to understand how it should be used.</div><p style="text-align:left;"><span style="color:inherit;"><br></span></p><div style="text-align:left;"><div>I’ll dig into things a bit further in future posts as I’d like pursue some experimentation to understand pros and cons of different approaches. In the meantime check out the <a href="https://developers.google.com/optimization/cp/cp_solver" title="examples" target="_blank">examples</a>, they really are quite comprehensive for standard problems.</div></div><p style="text-align:left;"><span style="color:inherit;"><br></span></p><div style="text-align:left;">As a postscript, the project was successfully delivered using OR-Tools , however due to the modeled variables and constraints, solution speed was pretty slow. This was not unexpected and not a reflection of OR-Tools since the model contained thousands of variables … but it would have been nice to find a silver bullet!</div><div style="text-align:left;"><br></div></div>
</div></div></div></div></div></div> ]]></content:encoded><pubDate>Thu, 02 May 2019 10:18:04 +0930</pubDate></item><item><title><![CDATA[Hello World]]></title><link>https://www.prescient.consulting/blogs/post/Hello-World</link><description><![CDATA[<img align="left" hspace="5" src="https://www.prescient.consulting/files/new-logo-favicon-sm3.png"/>Hello World post]]></description><content:encoded><![CDATA[<div class="zpcontent-container blogpost-container "><div data-element-id="elm_g9c3js4US6e1-frp1Ff58A==" data-element-type="section" class="zpsection "><style type="text/css"></style><div class="zpcontainer-fluid zpcontainer"><div data-element-id="elm_GWuF-xsJQFq9mu_W0HpIhw==" data-element-type="row" class="zprow zprow-container zpalign-items- zpjustify-content- " data-equal-column=""><style type="text/css"></style><div data-element-id="elm_Q9rI1j0vToG72eyxyJFV1A==" data-element-type="column" class="zpelem-col zpcol-12 zpcol-md-12 zpcol-sm-12 zpalign-self- zpdefault-section zpdefault-section-bg "><style type="text/css"> [data-element-id="elm_Q9rI1j0vToG72eyxyJFV1A=="].zpelem-col{ background-color:#000000; background-image:unset; } </style><div data-element-id="elm_P7-KoAphR_uNNU_M3icIVQ==" data-element-type="heading" class="zpelement zpelem-heading "><style></style><h2
 class="zpheading zpheading-align-left " data-editor="true"><span style="font-family:&quot;Courier New&quot;;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:rgb(236, 240, 241);">&nbsp; &nbsp;&gt;&gt;&gt; print('Hello World')<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Hello World</span></span><br></h2></div>
<div data-element-id="elm_-3ELBVrON_ajQoy73JGHow" data-element-type="spacer" class="zpelement zpelem-spacer "><style> div[data-element-id="elm_-3ELBVrON_ajQoy73JGHow"] div.zpspacer { height:8px; } @media (max-width: 768px) { div[data-element-id="elm_-3ELBVrON_ajQoy73JGHow"] div.zpspacer { height:calc(8px / 3); } } </style><div class="zpspacer " data-height="8"></div>
</div></div></div></div></div></div> ]]></content:encoded><pubDate>Wed, 03 Oct 2018 14:29:11 +0930</pubDate></item></channel></rss>