# Reversing Differences

Fellow blogger Håkan Kjellerstrand posted an interesting question on OR Stack Exchange recently. Starting from a list of integers, it is trivial to compute the list of all pairwise absolute differences, but what about going in the other direction? Given the pairwise (absolute) differences, with duplicates removed, can you recover the source list (or a …

More

# Collections of CPLEX Variables

Recently, someone asked for help online regarding an optimization model they were building using the CPLEX Java API. The underlying problem had some sort of network structure with $$N$$ nodes, and a dynamic aspect (something going on in each of $$T$$ periods, relating to arc flows I think). Forget about solving the problem: the program …

More

# Generic Callback Changes in CPLEX 12.10

CPLEX 12.10 is out, and there have been a few changes to the new(ish) generic callbacks. Rather than go into them in detail (and likely screw something up), I’ll just point you to the slides for a presentation by Daniel Junglas of IBM at the 2019 INFORMS Annual Meeting. I’ve written about half a dozen …

More

# Greedy Methods Can Be Exact

We generally sort optimization algorithms (as opposed to models) into two or three categories, based on how certain we are that solutions will be either optimal or at least “good”. An answer by Michael Feldmeier to a question I posted on OR Stack Exchange neatly summarizes the categories: exact methods eventually cough up provably optimal …

More

# 1-D Cutting Stock with Overlap

An interesting variation of the 1-D cutting stock problem was posed on OR Stack Exchange. Rather than having a specified demand for various size cut pieces, the requirement is to cut pieces to cover a specified number of units of fixed lengths. Moreover, you can use multiple pieces to cover one target unit, but if …

More

# A Value-ordered Java Map

For a project I’m working on (in Java), I wanted to store pairs of items in a key-value map. The catch is that I need the items sorted according to the values, not the keys. Java provides an efficient, presorted mapping in the TreeMap class, but it sorts on the keys, not the values. Revering …

More

# Numerical Inaccuracy (Linear Algebra Edition)

“There are three kinds of lies: lies, damned lies, and statistics.” The origin of the statement is lost in time, but the sentiment lives on. I’m tempted to give it a 21st century update. “There are three kinds of lies: lies, damned lies, and floating point arithmetic.” I am currently working on a research project …

More

# Using Java Collections with CPLEX

Disclaimer: What follows is specific to Java, but with some name changes will also apply to C++. If you are using one of the other programming APIs for CPLEX, something analogous may exist, but I would have no idea about it. I’ve seen a few questions by CPLEX users on forums recently that suggest the …

More

# Evaluating Expressions in CPLEX

There’s a feature in the Java API for CPLEX (and in the C++ and C APIs; I’m not sure about the others) that I don’t see mentioned very often, possibly because use cases may not arise all that frequently. It became relevant in a recent email exchange, though, so I thought I’d highlight it. As …

More

# R v. Python

A couple of days ago, I was having a conversation with someone that touched on the curriculum for a masters program in analytics. One thing that struck me was requirement of one semester each of R and Python programming. On the one hand, I can see a couple of reasons for requiring both: some jobs …

More

# A Java Container for Parameters

A few days ago, I posted about a Swing class (and supporting stuff) that I developed to facilitate my own computations research, and which I have now made open-source in a Bitbucket repository. I finally got around to cleaning up another Java utility class I wrote, and which I use regularly in experiments. I call …

More

# A Swing Platform for Computational Experiments

Most of my research involves coding algorithms and running computational experiments with them. It also involves lots of trial-and-error, both with the algorithms themselves and with assorted parameters that govern their functioning. Back in the Dark Ages, I did all this with programs that ran at a command prompt (or, in Linux terms, in a …

More

# Indicator Constraints v. Big M

Way, way back I did a couple of posts related to how to model “logical indicators” (true/false values that control enforcement of constraints): Logical Indicators in Mathematical Program Indicator Implies Relation The topic ties in to the general issue of “big M” model formulations. Somewhere around version 10, CPLEX introduced what they call indicator constraints, …

More

# Naming CPLEX Objects

A CPLEX user recently asked the following question on a user forum: “Is there a way to print the constraints as interpreted by CPLEX immediately after adding these constraints using addEq, addLe etc.” The context for a question like this is often an attempt to debug either a model or the code creating the model. …

More

# How to Crash CPLEX

A question elsewhere on the blog reminded me that some users of the CPLEX programming APIs are not conscious of a “technicality” that, when violated, might cause CPLEX to crash (or at least throw an exception). The bottom line can be stated easily enough: modifying a CPLEX model while solving it is a Bozo no-no. …

More

# Randomness: Friend or Foe?

I spent a chunk of the weekend debugging some code (which involved solving an optimization problem). There was an R script to setup input files and a Java program to process them. The Java program included both a random heuristic to get things going and an integer program solved by CPLEX. Randomness in algorithms is …

More

# CPLEX Callbacks: ThreadLocal v. Clone

A while back, I wrote a post about the new (at the time) “generic” callbacks in CPLEX, including a brief discussion of adventures with multiple threads. A key element was that, with generic callbacks, IBM was making the user more responsible for thread safety. In that previous post, I explored a few options for doing …

More

# Pseudocode in LyX Revisited

This post is strictly for users of LyX. In a previous post I offered up a LyX module for typesetting pseudocode. Unfortunately, development of that module bumped up against some fundamental incompatibilities between the algorithmicx package and the way LyX layouts work. The repository for it remains open, but I decided to shift my efforts …

More

# Guessing Pareto Solutions: A Test

In yesterday’s post, I described a simple multiple-criterion decision problem (binary decisions, no constraints), and suggested a possible way to identify a portion of the Pareto frontier using what amounts to guesswork: randomly generate weights; use them to combine the multiple criteria into a single objective function; optimize that (trivial); repeat ad nauseam. I ran …

More

# Guessing Pareto Solutions

One of the challenges of multiple-criteria decision-making (MCDM) is that, in the absence of a definitive weighting or prioritization of criteria, you cannot talk meaningfully about a “best” solution. (Optimization geeks such as myself tend to find that a major turn-off.) Instead, it is common to focus on Pareto efficient solutions. We can say that …

More

# Binary / Integer Conversion in R

I’ve been poking around in R with an unconstrained optimization problem involving binary decision variables. (Trust me, it’s not as trivial as it sounds.) I wanted to explore the entire solution space. Assuming $$n$$ binary decisions, this means looking at the set $$\{0,1\}^n$$, which contains $$2^n$$ 0-1 vectors of dimension $$n$$. For reasons I won’t …

More

Yesterday I had a rather rude reminder (actually, two) of something I’ve known for a while. I was running a Java program that uses CPLEX to solve an integer programming model. The symptoms were as follows: shortly after the IP solver run started, I ran out of RAM, the operating system started paging memory to …

More

# Of Typewriters and Permutations (V)

Okay, this is the last post on the subject. I promise! If you’re coming into this movie on the last reel, you may need to skim the last few posts to see what it’s about. I’m trying not to repeat myself too much. To summarize where we are at: Hardmath123 posted a solution (generated by …

More

# Of Typewriters and Permutations (IV)

I’m continuing the recent theme of solving a quadratic assignment problem that lays out the 26 letters of the English alphabet on a one-dimensional “keyboard” for an 18th century typewriter. I thought this would be the last post, but something new turned up, so there will likely be one more. In the blog post that …

More

# Of Typewriters and Permutations (III)

This continues the discussion (okay, monologue) from the two previous posts about the problem of laying out a one-dimensional typewriter keyboard. This is not the last post in the series, but I can at least guarantee that the series is converging. In the previous post, I gave a MIP model (named MIP1) that used binary …

More

# Of Typewriters and Permutations (II)

This continues my previous post about the problem of optimally laying out a one-dimensional typewriter keyboard, where “optimally” is taken to mean minimizing the expected amount of lateral movement to type a few selected books. As I noted there, Nate Brixius correctly characterized the problem as a quadratic assignment problem (QAP). I’ll in fact try …

More

# Of Typewriters and Permutations (I)

This is going to be the first of a few posts on the same problem. My efforts are based on a blog post by Nate Brixius (@natebrix) titled “Optimizing 19th Century Typewriters“, which in turn is based on a post titled “Tuning a Typewriter” by “Hardmath123”. As the image in Hardmath123’s post shows, an old …

More

# Stepwise Regression Code Revisited

I’ve added a few more tweaks to the stepwise regression code I published back in 2011. (If you wish, see here for the original post and here for a subsequent update.) The code does stepwise regression using F tests (or, equivalently, p-values of coefficients), which is a bit old fashioned but apparently how it is …

More

# Pseudocode in LyX

Fair warning: This post is for LyX users only. When I’m writing a paper or presentation in LaTeX (using LyX, of course) and want to include a program chunk or algorithm in pseudocode, I favor the algorithmicx package (and specifically the algpseudocode style). There being no intrinsic support for the package in LyX, I have …

More

# B.S.-ing Precisely

In a recent blog post titled “Excessive Precision“, John D. Cook points out the foolishness of articulating results to an arbitrarily high degree of precision when the inputs are themselves not that precise. To quote him: Excessive precision is not the mark of the expert. Nor is it the mark of the layman. It’s the …

More

# Coordinating Variable Signs

Someone asked me today (or yesterday, depending on whose time zone you go by) how to force a group of variables in an optimization model to take the same sign (all nonpositive or all nonnegative). Assuming that all the variables are bounded, you just need one new binary variable and a few constraints. Assume that …

More

# Choosing “Big M” Values

I seem to bring up “big M” models a lot, so apologies if I end up repeating myself in places here. Not long ago, someone passed along highlights of a “big M” type model to me and asked if he could somehow reformulate to get rid of $$M$$. I did not see any good way …

More

# Adding Items to a Sequence

A question posed on OR-Exchange in 2017 asked the following: Given a tour of nodes, how does one best add two new nodes while respecting the ordering of the original tour. Specifically, the author began with a tour 0 – 1 – 2 – 4 – 6 – 0 (where node 0 is a depot) …

More

# NP Confusion

I just finished reading a somewhat provocative article on the CIO website, titled “10 reasons to ignore computer science degrees” (when hiring programmers). While I’m not in the business of hiring coders (although I recent was hired as a “student programmer” on a grant — the Universe has a sense of humor), I find myself …

More

# Selecting Box Sizes

Someone posted an interesting question about box sizes on Mathematics Stack Exchange. He (well, his girlfriend to be precise) has a set of historical documents that need to be preserved in boxes (apparently using a separate box for each document). He wants to find a solution that minimizes the total surface area of the boxes …

More

More

# Finding a “Core Point”

In a famous (or at least relatively famous) paper [1], Magnanti and Wong suggest a method to accelerate the progress of Benders decomposition for certain mixed-integer programs by sharpening “optimality” cuts. Their approach requires the determination of what they call a core point. I’ll try to follow their notation as much as possible. Let $$Y$$ …

More

# Ordering Index Vector with Java Streams

I bumped up against the following problem while doing some coding in Java 8 (and using streams where possible). Given a vector of objects $$x_1, \dots, x_N$$ that come from some domain having an ordering $$\le$$, find the vector of indices $$i_1, \dots, i_N$$ that sorts the original values into ascending order, i.e., such that …

More

# Creating A New MIME Type

I struggled a bit this afternoon creating a new MIME type and associating it with a particular application, so I’m going to archive the solution here for future reference. This was on a Linux Mint system, but I found the key information in a GNOME documentation page, so I suspect it works for Ubuntu and …

More

# Benders Decomposition with Generic Callbacks

Brace yourself. This post is a bit long-winded (and arguably geekier than usual, which is saying something). Also, it involves CPLEX 12.8, which will not ship until some time next month. I have an updated version of an old example, solving a fixed charge transportation problem using Benders decomposition. The example (using Java, naturally) is …

More

As I noted in yesterday’s post, one of the major changes associated with the new “generic” callback structure in CPLEX is that users now bear the responsibility of making their callbacks thread-safe. As I also noted yesterday, this is pretty new stuff for me. So I’m going to try to share what I know about thread …

More

# CPLEX 12.8: Generic Callbacks

IBM is getting ready to release CPLEX 12.8, and I had the opportunity to attend a presentation about by Xavier Nodet at the 2017 INFORMS annual meeting. Here are links to two presentations by Xavier: CPLEX Optimization Studio 12.8 – What’s New and CPLEX 12.8 – the Generic Callback. As with any new release, there …

More

# Minimizing a Median

$$\def\xorder#1{x_{\left(#1\right)}} \def\xset{\mathbb{X}} \def\xvec{\mathbf{x}}$$A somewhat odd (to me) question was asked on a forum recently. Assume that you have continuous variables $$x_{1},\dots,x_{N}$$ that are subject to some constraints. For simplicity, I’ll just write $$\xvec=(x_{1},\dots,x_{N})\in\xset$$. I’m going to assume that $$\xset$$ is compact, and so in particular the $$x_{i}$$ are bounded. The questioner wanted to …

More

# Updated Stepwise Regression Function

Back in 2011, when I was still teaching, I cobbled together some R code to demonstrate stepwise regression using F-tests for variable significance. It was a bit unrefined, not intended for production work, and a few recent comments on that post raised some issues with it. So I’ve worked up a new and (slightly) improved …

More