diff --git a/nl-writer2/examples/c/nlsol_ex_c_sol.c b/nl-writer2/examples/c/nlsol_ex_c_sol.c index d165711f0..00ce2657e 100644 --- a/nl-writer2/examples/c/nlsol_ex_c_sol.c +++ b/nl-writer2/examples/c/nlsol_ex_c_sol.c @@ -1,4 +1,6 @@ #include +#include +#include #include "nlsol_ex_c_sol.h" @@ -29,6 +31,65 @@ void OnSolveCode(void* p_user_data, int sc) { pex->solve_code_ = sc; } +void OnIntSuffix( + void* p_user_data, NLW2_SuffixInfo_C si, void* p_api_data) { + CAPIExample* pex = (CAPIExample*)p_user_data; + int nitems_max[4] = {pex->n_var, pex->n_con, pex->n_obj, 1}; + int kind = si.kind_; + int nmax = nitems_max[kind & 3]; // {vars, cons, objs, 1} + const char* name = si.name_; + const char* table = si.table_; + printf("SUFFIX '%s': kind=%d\n", name, kind); + if (table && strlen(table)) + printf("SUFFIX TABLE:\n%s\n", table); + int i; + int v; + printf("%s", "NON-ZERO VALUES:"); + while (NLW2_IntSuffixNNZ(p_api_data)) { + NLW2_ReadIntSuffixEntry(p_api_data, &i, &v); + printf(" (%d, %d)", i, v); + if (i<0 || i>=nmax) { + NLW2_ReportIntSuffixError( + p_api_data, "bad suffix element index"); + return; + } + } + if (NLW2_IntSuffixReadOK(p_api_data)) // Can check + printf(" ...%s\n", "OK"); + else + printf(" ...%s\n", "FAILURE"); +} + +void OnDblSuffix( + void* p_user_data, NLW2_SuffixInfo_C si, void* p_api_data) { + CAPIExample* pex = (CAPIExample*)p_user_data; + int nitems_max[4] = {pex->n_var, pex->n_con, pex->n_obj, 1}; + int kind = si.kind_; + int nmax = nitems_max[kind & 3]; // {vars, cons, objs, 1} + const char* name = si.name_; + const char* table = si.table_; + printf("SUFFIX '%s': kind=%d\n", name, kind); + if (table && strlen(table)) + printf("SUFFIX TABLE:\n%s\n", table); + int i; + double v; + printf("%s", "NON-ZERO VALUES:"); + while (NLW2_DblSuffixNNZ(p_api_data)) { + NLW2_ReadDblSuffixEntry(p_api_data, &i, &v); + printf(" (%d, %g)", i, v); + if (i<0 || i>=nmax) { + NLW2_ReportDblSuffixError( + p_api_data, "bad suffix element index"); + return; + } + } + if (NLW2_DblSuffixReadOK(p_api_data)) // Can check + printf(" ...%s\n", "OK"); + else + printf(" ...%s\n", "FAILURE"); +} + + NLW2_SOLHandler2_C MakeSOLHandler2_C(CAPIExample* pex) { NLW2_SOLHandler2_C result = NLW2_MakeSOLHandler2_C_Default(); @@ -42,6 +103,8 @@ NLW2_SOLHandler2_C MakeSOLHandler2_C(CAPIExample* pex) { result.OnPrimalSolution = OnPrimalSolution; result.OnObjno = OnObjno; result.OnSolveCode = OnSolveCode; + result.OnIntSuffix = OnIntSuffix; + result.OnDblSuffix = OnDblSuffix; return result; }