Coder Social home page Coder Social logo

Comments (1)

maxschaller avatar maxschaller commented on July 16, 2024

@AlessandroZavoli that's totally possible. Let's have a look at the main c file generated for the default nonnegative least squares example, nonneg_LS/c/src/cpg_example.c. It includes all necessary headers, updates parameter values, solves the problem instance, and prints the results.

/*
Auto-generated by CVXPYgen on April 02, 2024 at 15:24:11.
Content: Example program for updating parameters, solving, and inspecting the result.
*/

#include <stdio.h>
#include "cpg_workspace.h"
#include "cpg_solve.h"

static int i;

int main(int argc, char *argv[]){

  // Update first entry of every user-defined parameter
  cpg_update_A(0, 1.76405234596766402611);
  cpg_update_b(0, 2.24089319920145779719);

  // Solve the problem instance
  cpg_solve();

  // Print objective function value
  printf("obj = %f\n", CPG_Result.info->obj_val);

  // Print primal solution
  for(i=0; i<2; i++) {
    printf("x[%d] = %f\n", i, CPG_Result.prim->x[i]);
  }

  // Print dual solution
  for(i=0; i<2; i++) {
    printf("d0[%d] = %f\n", i, CPG_Result.dual->d0[i]);
  }

  return 0;

}

In general, you can update your parameter value, say the (i, j)-th entry of matrix M (dimension m by n) to value 3.0, by calling

cpg_update_M(i + j * m, 3.0);

Note that matrices are stored in column-major format. If your parameter is a vector or scalar, the first argument to the update function is just the vector index or 0.

When you are using the Python interface and M is a cp.Parameter((m, n)), just write

M.value[i, j] = 3.0

Please let me know if you have any further questions.

from cvxpygen.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.