#pragma once #include #include /* 宏定义 */ #define INF 1.0E30 #define malloc malloc #define FREE free /* 变量类型定义 */ typedef struct cmscp_floatDemat { // 浮点型稠密矩阵 int m; // 行 int n; // 列 double* v; // 逐列存储矩阵的每一个元素 }cmscp_floatDemat; typedef struct intDemat { // 整数型稠密矩阵 int m; // 行 int n; // 列 int* v; // 逐列存储矩阵的每一个元素 }intDemat; typedef struct cmscp_crsSpmat { // 行压缩存储格式 int m;// 行 int n;// 列 int* ptrRow;// 每行首个非零元素位置 int* idxCol;// 非零元素列坐标 double* v;// 逐行存储矩阵的每一个非零元素 }cmscp_crsSpmat; typedef struct cmscp_ccsSpmat {// 列压缩存储格式 int m;// 行 int n;// 列 int* ptrCol;// 每列首个非零元素位置 int* idxRow;// 非零元素行坐标 double* v;// 逐列存储矩阵的每一个非零元素 }cmscp_ccsSpmat; typedef struct cmscp_trajInfo { // 轨迹信息变量结构体 double initialtime; double finaltime; cmscp_floatDemat* state; cmscp_floatDemat* control; double* parameter; }cmscp_trajInfo; typedef struct cmscp_stopInfo { int isStop; double absTol; }cmscp_stopInfo; typedef struct cmscp_trustInfo { int numState; }cmscp_trustInfo; /* 序列凸优化算法 */ typedef struct cmscp_solverInfo { char* name; int maxit; double abstol; double reltol; double feastol; int verbose; }cmscp_solverInfo; typedef struct cmscp_scp { int maxIter; int cntIter; double* obj; cmscp_solverInfo* solver; }cmscp_scp; /* 问题约束边界结构体 */ typedef struct cmscp_boundscale { double lower; double upper; }cmscp_boundscale; typedef struct cmscp_boundvec { double* lower; double* upper; }cmscp_boundvec; typedef struct cmscp_boundcone { cmscp_boundvec* nl; double* soc; }cmscp_boundcone; typedef struct cmscp_boundPhase { cmscp_boundscale* initialtime; cmscp_boundscale* finaltime; cmscp_boundvec* initialstate; cmscp_boundvec* state; cmscp_boundvec* finalstate; cmscp_boundvec* control; cmscp_boundvec* parameter; cmscp_boundcone* path; cmscp_boundcone* endpoint; cmscp_boundcone* linkage; }cmscp_boundPhase; typedef struct cmscp_bound { cmscp_boundPhase** phase; cmscp_boundcone* event; }cmscp_bound; /* 问题维数结构体 */ typedef struct cmscp_dimension1 { int n; int* q; }cmscp_dimension1; typedef struct cmscp_dimension2 { int nl; cmscp_dimension1* soc; }cmscp_dimension2; typedef struct cmscp_dimensionPhase { int state; int control; int parameter; cmscp_dimension2* path; cmscp_dimension2* endpoint; cmscp_dimension2* linkage; }cmscp_dimensionPhase; typedef struct cmscp_dimension { cmscp_dimensionPhase** phase; cmscp_dimension2* event; }cmscp_dimension; /* 问题信赖域结构体 */ typedef struct cmscp_trustWeihgt { double initialtime; double finaltime; double* state; double* control; double* parameter; }cmscp_trustWeihgt; typedef struct cmscp_trustPhase { cmscp_trustWeihgt* weight; double hardRadius; double softPenaWeight; }cmscp_trustPhase; typedef struct cmscp_trust { char* model; double merit; cmscp_trustPhase** phase; }cmscp_trust; /* 问题函数名称结构体 */ typedef struct cmscp_contInput { void* auxdata; double* state; double* control; double* parameter; }cmscp_contInput; typedef struct cmscp_endpInput { void* auxdata; double initialtime; double* initialstate; double finaltime; double* finalstate; double* parameter; }cmscp_endpInput; typedef struct cmscp_linkInput { void* auxdata; // auxdata是辅助参数,与问题相关,事先不确定其类型 double leftFinTime; double* leftFinState; double* leftParameter; double rightIniTime; double* rightIniState; double* rightParameter; }cmscp_linkInput; typedef struct cmscp_objEventInputPhase { double initialtime; double finaltime; double* initialstate; double* finalstate; double* parameter; }cmscp_objEventInputPhase; typedef struct cmscp_objEventInput { void* auxdata; // auxdata是辅助参数,与问题相关,事先不确定其类型 cmscp_objEventInputPhase** phase; }cmscp_objEventInput; typedef void (*cmscp_continuous)(double*, double*, cmscp_contInput*); typedef void (*cmscp_endpoint)(double*, cmscp_endpInput*); typedef void (*cmscp_linkage)(double*, cmscp_linkInput*); typedef void (*cmscp_objEvent)(double*, double*, cmscp_objEventInput*); typedef void (*cmscp_objEventDepend)(intDemat*); typedef void (*cmscp_contDepend)(intDemat*, int, void*); typedef void (*cmscp_endpDepend)(intDemat*, int, void*); typedef void (*cmscp_linkDepend)(intDemat*, int, void*); typedef void (*cmscp_getIniRefTraj)(cmscp_trajInfo**, void*); typedef int* (*cmscp_stopCondition)(int, cmscp_trajInfo**, cmscp_trajInfo**, void*); typedef void (*cmscp_updateMeshInfo)(int, cmscp_trajInfo**, cmscp_trajInfo**, void*); typedef void (*cmscp_updateTrustInfo)(int, cmscp_trajInfo**, cmscp_trajInfo**, void*); typedef void (*cmscp_updateRefTraj)(cmscp_trajInfo**, cmscp_trajInfo**, void*); typedef struct cmscp_functionsPhase { cmscp_continuous continuous; cmscp_endpoint endpoint; cmscp_linkage linkage; }cmscp_functionsPhase; typedef struct cmscp_functions { /* 各段函数 */ cmscp_functionsPhase** phase; /* 目标函数和事件函数 */ cmscp_objEvent objEvent; /* 手动稀疏模式所需相关性函数 */ cmscp_objEventDepend objEventDepend; cmscp_contDepend contDepend; cmscp_endpDepend endpDepend; cmscp_linkDepend linkDepend; /* 序列线性化所需函数 */ cmscp_getIniRefTraj getIniRefTraj; cmscp_stopCondition stopCondition; cmscp_updateMeshInfo updateMeshInfo; cmscp_updateTrustInfo updateTrustInfo; cmscp_updateRefTraj updateRefTraj; }cmscp_functions; /* 每段的离散点 */ typedef struct cmscp_mesh { int num; double* node; }cmscp_mesh; /* 问题设置参数结构体 */ typedef struct cmscp_setup { void* auxdata; // 不确定类型,用空指针 int numPhase; // 分段数 char* sparseModel; // 稀疏模式 double derStep; // 求导步长 cmscp_scp* scpInfo; // 序列凸优化参数 //cmscp_functions* functions; cmscp_mesh** oldMesh; cmscp_mesh** mesh; cmscp_trust* trust; cmscp_dimension* dimension; cmscp_functions* functions; cmscp_bound* bounds; }cmscp_setup; int cmscp(cmscp_trajInfo** optTraj, cmscp_setup* setup);