# 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

# 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

# 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

# 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

# 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

# Usefulness of Computer Science: An Example

I thought I would follow up on my June 29 post, “Does Computer Science Help with OR?“, by giving a quick example of how exposure to fundamentals of computer science recently helped me. A current research project involves optimization models containing large numbers of what are basically set covering constraints, constraints of the form \(\displaystyle …

More

# Does Computer Science Help with OR?

Fair warning: tl/dr. After reading a blog post yesterday by John D. Cook, “Does computer science help you program?“, I decided to throw in my two cents (convert to euros at your own risk) on a related topic: does computer science (which I will extend to including programming) help you as an OR/IE/management science/analytics professional? …

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

# rJava: The Gift That Keeps On Giving

I’ve written not once but twice before (in 2011 and 2015) about the hassles of getting the rJava package to work with R. Every time I think I have a fix for it, someone changes something somewhere and the previous fix no longer works. I had to reinstall rJava today (from the Canonical repositories) after …

More

# Interactive R Plots with GGPlot2 and Plotly

I refactored a recent Shiny project, using Hadley Wickham’s ggplot2 library to produce high quality plots. One particular feature the project requires is the ability to hover over a plot and get information about the nearest point (generally referred to as “hover text” or a “tool tip”). There are multiple ways to turn static ggplots …

More

# Formatting in a Shiny App

I’ve been updating a Shiny (web-based interactive R) application, during the course of which I needed to make a couple of cosmetic fixes. Both proved to be oddly difficult. Extensive use of Google (I think I melted one of their cloud servers) eventually turned up enough clues to get both done. I’m going to record …

More

# Autocorrupt in R

You know that “autocomplete” feature on your smart phone or tablet that occasionally (or, in my case, frequently) turns into an “autocorrupt” feature? I just ran into it in an R script. I wrote a web-based application for a colleague that lets students upload data, run a regression, ponder various outputs and, if they wish, …

More

# Shiny Hack: Vertical Scrollbar

I bumped into a scrolling issue while writing a web-based application in Shiny, using the shinydashboard package. Actually, there were two separate problems. The browser apparently cannot discern page height. In Firefox and Chrome, this resulted in vertical scrollbars that could scroll well beyond the bottom of a page. That’s mildly odd, but not a …

More

# Tabulating Prediction Intervals in R

I just wrapped up (knock on wood!) a coding project using R and Shiny. (Shiny, while way cool, is incidental to this post.) It was a favor for a friend, something she intends to use teaching an online course. Two of the tasks, while fairly mundane, generated code that was just barely obscure enough to …

More

# The rJava Nightmare

I like R. I like Java. I hate the rJava package, or more precisely I hate installing or updating it. Something (often multiple somethings) always goes wrong. I forget that for some reason I need to invoke root privileges when installing it. It needs a C++ library that I could swear I have, except I …

More

# Hell Hath No Fury Like a Dependency Scorned

There is a recent package for the R statistics system named “Radiant”, available either through the CRAN repository or from the author’s GitHub site. It runs R in the background and lets you poke at data in a browser interface. If you are looking for a way to present data to end-users and let them …

More

# Updated Java Utilities for CPLEX and CP Optimizer

I just finished adding a feature to a utility library I use in Java projects that employ either CPLEX or CP Optimizer. In addition, I moved the files to a new home. The library is free to use under the Eclipse Public License 1.0. The code is mentioned in previous posts, so I’ll just quickly …

More

# An SSH Glitch

Something weird happened with SSH today, and I’m documenting it here in case it happens again. I was minding my own business, doing some coding, on a project that is under version control using Git. After committing some changes, I was ready to push them up to the remote (a GitLab server here at Michigan …

More

# Formulating Optimization Models

Periodically, on OR Exchange and other forums, I encounter what are surely homework problems involving the construction of optimization models. “The Acme Anvil Corporation makes two types of anvils, blue ones and red ones. Blue anvil use 185 kg. of steel and have a gross revenue of \$325 each; red anvils …” Really? Does anyone …

More

# Coding for kids

I’ve been trying to get my kids interested in coding. I found this nice game called Lightbot, in which one writes simple programs that control the discrete movements of a bot. It’s very intuitive and in just one morning my kids learned quite a bit about the idea of an algorithm and the notion of …

More

# Thunar Slow-down Fixed

My laptop is not exactly a screamer, but it’s adequate for my purposes. I run Linux Mint 17 on it (Xfce desktop), which uses Thunar as its file manager. Not too long ago, I installed the RabbitVCS version control tools, including several plugins for Thunar needed to integrate the two. Lately, Thunar has been incredibly …

More

# Parsing Months in R

As part of a recent analytics project, I needed to convert strings containing (English) names of months to the corresponding cardinal values (1 for January, …, 12 for December). The strings came from a CSV file, and were translated by R to a factor when the file was read. The factor had more than 12 …

More

# Python usage survey 2014

Remember that Python usage survey that went around the interwebs late last year? Well, the results are finally out and I’ve visualized them below for your perusal. This survey has been running for two years now (2013-2014), so where we have data for both years, I’ve charted the results so we can see the changes …

More

# Remotely Mounting a USB Drive

As I try to retire an old PC running Mythbuntu in favor of a new replacement, I continue to learn things about Linux … with a gun to my head, as it were. Without getting into the gory details, I can no longer work directly on the old PC — I can’t get a functioning …

More

# The post-apocalyptic world of binary containers

The apocalypse is nigh. Soon, binary executables and containers in object stores will join the many Web-based pipelines and the several virtual machine images on the dystopic wasteland of “reproducible science.” Anyway. I had a conversation a few weeks back with a senior colleague about container-based approaches (like Docker) wherein they advocated the shipping around …

More

# RStudio Git Support

One of the assignments in the R Programming MOOC (offered by Johns Hopkins University on Coursera) requires the student to set up and utilize a (free) Git version control repository on GitHub. I use Git (on other sites) for other things, so I thought this would be no big deal. I created an account on …

More

# What version of Python should we use to for computational science courses?

Brian O’Shea (a physics prof at Michigan State) asked me the following, and I thought I’d post it on my blog to get a broader set of responses. I know the answer is “Python 3”, but I would appreciate specific thoughts from people with experience either with the specific packages below, or in teaching Python …

More

# Java Gotchas

I was writing what should have been (and, in the end, was) a very simple Java program yesterday. It wound up taking considerably longer than it should have, due to my tripping over two “gotchas”, which I will document here for my own benefit (the next time I trip over them). Issue 1: Importing from …

More

# Teaching Kids to Write Code Through Writing Stories

In the last couple of years there’s been a noticeable push for developing programming and computer science skills in childhood education. In a blog post on MiddleWeb: All About the Middle Grades, Mark Gerl, writes about his experience at Computer Science Education Week. His post gets at the interconnectedness of programming languages, gaming, and student …

More

# Fewer Zeros

A question I saw online not too long ago caused me a flashback to my days teaching linear programming (LP) to masters students. The poster had developed an optimization model — I can’t recall if it was an LP, a quadratic program (QP) or a mixed-integer program (MIP) — and had no problem solving it. …

More

# NetBeans 8 Update Bugs

An update to the NetBeans IDE (8.0 patch 2) this morning seems to have introduced some problems that I was fortunately able to work around. I’ll document them here in case anyone else runs into them. For some context, when I opened NetBeans, it correctly showed three projects in the project navigator, the main project …

More

# Learning R

I have recently dedicated myself to learning R, a programming language and environment for focusing largely on statistical analysis and computing. The benefit of using R over other statistical computing packages is that it is free, open-source, and has a hugely active community around its use.  R can be used cross-platform  (PCs, Macs, and Linux) …

More

# Some thoughts on research coding and Stupidity Driven Development

I’m on a European trip that involves several plane flights accompanied by long airport stays, and I just used some of that time to do a bit of tedious coding on khmer. The coding I did was to add proper exception handling to khmer’s internal file loading routines (see the pull request). The old behavior …

More

# A Java Slider/Text Combo

A few years back I was coding (in Java, of course) the <shudder>GUI</shudder> for a research program. I needed to provide controls that would let a user specify priorities (0-100) scale for various things. Two possibilities occurred to me, with pretty much diametrically opposed strengths and weaknesses. Sliders have a few virtues. Grabbing and yanking …

More

# Setting CPLEX Parameters in Java Revisited

A bit more than a year and a half ago, I wrote some Java code to facilitate setting parameters for the CPLEX optimizer using their Concert API. Since then, I’ve added support for their CP Optimizer, and IBM has refactored the handling of parameters in CPLEX, necessitating an update to my code. This post (which …

More

# PyCon 2014: Community, community, community. Also, childcare.

There were lots of problems with PyCon this year. For example, the free, hi-speed wifi made you log in each day. And it was in Montreal, so one of my foreign students couldn’t come because he didn’t get a visa in time. The company booths were not centrally located. And, worst of all, the PyCon …

More

Codecademy is an excellent resource for learning new programming languages and coding techniques. They provide lessons and exercises for everything from basic HTML and CSS to JavaScript, PHP, jQuery, Ruby, Python and so much more. They even have projects for you to accomplish by utilizing programming languages to create and style various web features. They …

More

# CP Optimizer, Java and NetBeans

After years of coding CPLEX applications in Java, I’ve just started working with CP Optimizer (the IBM/ILOG constraint programming solver) … and it did not take me long to run into problems. As with CPLEX, you access CP Optimizer from Java through the Concert API. As always, I am using the NetBeans IDE to do …

More

# Mint Petra Odds and Ends

As I complete (hopefully) the upgrade of my home PC to Linux Mint 16 Petra (which appears to be commensurable with Ubuntu 13.10 Saucy Salamander), I’m making notes on glitches small and large. I initially had some display problems booting and resuming from hibernation. By “display problems” I mean totally corrupted displays, or what appeared …

More

# A few thoughts on code review of scientific code

Erica Check Hayden at Nature News wrote this article about a Mozilla Science Lab effort to bring code review to scientific code. Code review is an important part of many open source, startup, and corporate software development cultures, and the goal of the Mozilla effort is to See What Happens when you throw seasoned software …

More

# Learning Statistics with R, Part I

For my new job, I need to be doing some data analysis. While I love Python and the IPython Notebook, it is definitely time that I invest some effort in learning how to use R Stats. So, this blog post (maybe even a series?) documents what I am learning and how I believe it applies …

More

# Validity when Evaluating Learning

I want to spend some time writing about major topics that pertain to assessment. If you’re new to assessment or if you’re looking for ideas for how to do really good evaluation of educational interventions, then this is definitely something you should read. Today’s topic is validity. What is validity? Validity refers to the accuracy …

More

# Learning to Code

So it’s come to your attention that, *gulp*, you are going to have to learn to code something. This is happening more and more across disciplines: be it the explosion of interest in digital humanities, robust software or support data analysis, more and more graduate students are finding themselves moving beyond the WSYIWYG toolbars and …

More