R CVXR linear programming

Illustrated infographic summarizing: R CVXR linear programming

Here is the example that works:

Original source not working: http://rtutorial.altervista.org/lp_solvers.html
Thanks to Mark Neal for debugging: https://stackoverflow.com/questions/60909930/r-cvxr-matrix-multiplicati…

library(CVXR)
#create Variable objects that can be manipulated by the solver.
x<-Variable(3)
#coefficients for objective function
C <- matrix(c(2,4,3), nrow = 1)
#the Maximize function does not find a maximum for this function. It is creating an objective function object that the solver will be able to use.

objective<-Maximize(C %*% x)
#make a list of constraints. x[i] is the ith x variable
constraints<-list(3*x[1]+4*x[2]+2*x[3]<=60, 
                  2*x[1]+x[2]+2*x[3]<=40, 
                  x[1]+3*x[2]+2*x[3]<=80, 
                  x>=0)
#now we formulate the problem using the Problem function. this will create a "Problem" object for the solver
problem<-Problem(objective, constraints)
microbenchmark(
#now we can get the solution by calling solve. Now we can print out all the information we want.
ans<-solve(problem),
times=100
)
#show status
print(ans$status)
#show optimum value
print(ans$value)
#show values for variables
print(ans$getValue(x))

Latest articles

Build a weekly marketing report from GA4 and Google Ads with verified calculations, clear data caveats and a short AI draft to support your Monday meeting.

Before buying a GPU, test one real team workflow on existing hardware. A Linux pilot can show whether quality, memory, response times, and running costs add up.

Planning a Drupal relaunch? Set clear rules for content, translations, media and old URLs, with a practical checklist for approving the migration and launch.

Use AI for your online store’s alt text with a manageable pilot: map the images, generate suggestions in Danish, and check the results in WordPress and WooCommerce.

Supplier files need more than extraction. Here’s how to check coverage, match SKUs, resolve unclear units and prices, and test product data before a catalogue import.

Shorter TLS certificates leave less room for renewal problems. Check domain validation, scheduling, deployment and the certificate your customers actually receive.

AI image credentials can disappear during routine website processing. Learn how to test your CMS, optimizer, CDN, and publishing workflow end to end.

AI-based ticket analysis can uncover recurring complaints, product defects and gaps in documentation—without the company needing yet another chatbot.

OpenAI’s X.509 workload identity can replace API keys for the right workloads. This practical framework helps teams decide where to start safely.

WordPress 7.1 helps AI agents discover and invoke site abilities. Here is how to keep exposure, authentication and permission firmly separate.

Review Greg on Google

Greg Nowak Google Reviews

 

Written recommendations from Trafik og Veje, Aarhus Municipality (2011) and AgroTech (2010) — read them on LinkedIn.