Skip to main content
GrN.dk

Main navigation

  • Articles
  • Cases
  • Contact
  • Your Digital Project Manager
  • About Greg Nowak
  • Services
  • Portfolio
  • Container
    • Excel Freelancer
    • Kubuntu - tips and tricks
    • Linux Apache MySQL and PHP
    • News
    • Image Gallery
User account menu
  • Log in

Breadcrumb

  1. Home

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))

Last modified
2020-03-30
  • Log in to post comments

Review Greg on Google

Greg Nowak Google Reviews

 

Illustrated infographic summarizing: WordPress Supports Old PHP; Your Production Server Shouldn’t
WordPress Supports Old PHP; Your Production Server Shouldn’t
2026-08-01

WordPress still runs on legacy PHP, but compatibility is not a security policy. Build and test your upgrade path before PHP 8.2 support ends.

Illustrated infographic summarizing: The AI-built tool your team relies on needs an owner
The AI-built tool your team relies on needs an owner
2026-07-31

AI-built internal tools can become business-critical before anyone owns them. Here is how to secure, review, monitor, and retire them without blocking useful work.

Illustrated infographic summarizing: Your AI model has an expiry date: build the migration lane now
Your AI model has an expiry date: build the migration lane now
2026-07-30

AI models retire on a schedule. Learn how to map dependencies, test replacements, release safely and preserve a working rollback route.

Illustrated infographic summarizing: Copilot Has Repo-Level Metrics Now. What Should Teams Measure?
Copilot Has Repo-Level Metrics Now. What Should Teams Measure?
2026-07-29

GitHub’s repo-level Copilot metrics show where AI is active, but not whether it adds value. This scorecard connects usage with delivery, quality, and cost.

Illustrated infographic summarizing: Not Every AI Job Needs an Instant Answer: Batch the Backlog
Not Every AI Job Needs an Instant Answer: Batch the Backlog
2026-07-28

Move delay-tolerant AI work into dependable batch queues to cut processing costs without compromising quality, data controls, or urgent workflows.

Illustrated infographic summarizing: A stray Set-Cookie can waste your CDN: audit the cache at the edge
A stray Set-Cookie can waste your CDN: audit the cache at the edge
2026-07-27

Cloudflare Cache Response Rules can recover wasted CDN capacity, but first you need a route-level audit of public, personal and authenticated responses.

Illustrated infographic summarizing: Shorter TLS certificates expose every renewal you never automated
Shorter TLS certificates expose every renewal you never automated
2026-07-26

Shorter TLS lifetimes leave less room for manual handoffs and faulty deploy hooks. Build a renewal path that protects service availability.

Illustrated infographic summarizing: One Timeout, Two Orders: Make AI Actions Safe to Retry
One Timeout, Two Orders: Make AI Actions Safe to Retry
2026-07-25

A timed-out AI action may already have succeeded. Stable keys, durable ledgers, queues and stored results prevent a routine retry from duplicating real work.

Illustrated infographic summarizing: Your AI Visibility Dashboard Needs a Methodology, Not More Charts
Your AI Visibility Dashboard Needs a Methodology, Not More Charts
2026-07-24

A practical framework for measuring AI-search visibility with fixed prompts, repeated tests, separate metrics, retained evidence, and honest reporting.

Illustrated infographic summarizing: AI Admin APIs Are Here—But Your Directory Is Still the Source of Truth
AI Admin APIs Are Here—But Your Directory Is Still the Source of Truth
2026-07-23

New AI admin APIs can automate access and spend controls, but reliable governance still starts with authoritative directory data and clear ownership.

More articles
RSS feed

GrN.dk web platforms, web optimization, data analysis, data handling and logistics.