Comments (1)
@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)
- generate code failed TypeError: 'NoneType' object is not subscriptable HOT 2
- Example not working
- Adding new solvers is extremely difficult HOT 2
- SOC dimension issue HOT 1
- `generate_code` raises IndexError when `solver="CLARABEL"` HOT 2
- feature request: structs instead of global workspace HOT 1
- Regression with latest upgrade to cvxpy 1.4.0 HOT 2
- underflow in generated code HOT 3
- inconsistency in `cpg_csc` dimensions HOT 1
- SDP option in CLARABEL HOT 2
- Encountering challenges when integrating cvxpygen into existing projects. HOT 2
- generate_code raises TypeError HOT 1
- CPG Solver Produces 'primal infeasible' Solution for Conventionally Solvable Problem HOT 1
- Default solver is not setup in configuration HOT 2
- How to implement RK4 integration scheme in a DPP compliant manner HOT 12
- Would you eventually consider generating code in rust? HOT 1
- ECOS fails when solving second time HOT 3
- Solve time using C code with python wrapper varies based on the chosen solver HOT 14
- Compiled Clarabel code sometimes producing wrong results compared to cvxpy only HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cvxpygen.