From 39f6095e286967132fbd73aea204fbd9933514c6 Mon Sep 17 00:00:00 2001 From: giaf Date: Wed, 2 Sep 2020 17:27:58 +0200 Subject: [PATCH] add tree ocp qcqp test problem --- .travis.yml | 2 + test_problems/test_d_tree_ocp_qcqp.c | 1296 ++++++++++++++++++++++++++ tree_ocp_qp/x_tree_ocp_qcqp_res.c | 4 +- 3 files changed, 1300 insertions(+), 2 deletions(-) create mode 100644 test_problems/test_d_tree_ocp_qcqp.c diff --git a/.travis.yml b/.travis.yml index 7f1c0376..75410130 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,6 +30,7 @@ jobs: - make -C test_problems test_d_part_cond TARGET=AVX BLASFEO_PATH="${TRAVIS_BUILD_DIR}"/blasfeo PRINT=0 - make -C test_problems test_d_part_cond_qcqp TARGET=AVX BLASFEO_PATH="${TRAVIS_BUILD_DIR}"/blasfeo PRINT=0 - make -C test_problems test_d_tree_ocp TARGET=AVX BLASFEO_PATH="${TRAVIS_BUILD_DIR}"/blasfeo PRINT=0 + - make -C test_problems test_d_tree_ocp_qcqp TARGET=AVX BLASFEO_PATH="${TRAVIS_BUILD_DIR}"/blasfeo PRINT=0 - name: "Linux ARM64 C build" arch: arm64 @@ -54,6 +55,7 @@ jobs: - make -C test_problems test_d_part_cond TARGET=GENERIC BLASFEO_PATH="${TRAVIS_BUILD_DIR}"/blasfeo PRINT=0 - make -C test_problems test_d_part_cond_qcqp TARGET=GENERIC BLASFEO_PATH="${TRAVIS_BUILD_DIR}"/blasfeo PRINT=0 - make -C test_problems test_d_tree_ocp TARGET=GENERIC BLASFEO_PATH="${TRAVIS_BUILD_DIR}"/blasfeo PRINT=0 + - make -C test_problems test_d_tree_ocp_qcqp TARGET=GENERIC BLASFEO_PATH="${TRAVIS_BUILD_DIR}"/blasfeo PRINT=0 - name: "Linux AMD64 octave build" arch: amd64 diff --git a/test_problems/test_d_tree_ocp_qcqp.c b/test_problems/test_d_tree_ocp_qcqp.c new file mode 100644 index 00000000..99afcd54 --- /dev/null +++ b/test_problems/test_d_tree_ocp_qcqp.c @@ -0,0 +1,1296 @@ +/************************************************************************************************** +* * +* This file is part of HPIPM. * +* * +* HPIPM -- High-Performance Interior Point Method. * +* Copyright (C) 2019 by Gianluca Frison. * +* Developed at IMTEK (University of Freiburg) under the supervision of Moritz Diehl. * +* All rights reserved. * +* * +* The 2-Clause BSD License * +* * +* Redistribution and use in source and binary forms, with or without * +* modification, are permitted provided that the following conditions are met: * +* * +* 1. Redistributions of source code must retain the above copyright notice, this * +* list of conditions and the following disclaimer. * +* 2. Redistributions in binary form must reproduce the above copyright notice, * +* this list of conditions and the following disclaimer in the documentation * +* and/or other materials provided with the distribution. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * +* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * +* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * +* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * +* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * +* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * +* * +* Author: Gianluca Frison, gianluca.frison (at) imtek.uni-freiburg.de * +* * +**************************************************************************************************/ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "d_tools.h" + + + +#define KEEP_X0 0 + +// printing +#ifndef PRINT +#define PRINT 1 +#endif + + + +#if ! defined(EXT_DEP) +/* creates a zero matrix */ +void d_zeros(double **pA, int row, int col) + { + *pA = malloc((row*col)*sizeof(double)); + double *A = *pA; + int i; + for(i=0; iidx); + printf("stage = %d\n", (st.root+ii)->stage); + printf("real = %d\n", (st.root+ii)->real); + printf("idxkid = %d\n", (st.root+ii)->idxkid); + printf("dad = %d\n", (st.root+ii)->dad); + printf("nkids = %d\n", (st.root+ii)->nkids); + printf("kids ="); + for(jj=0; jj<(st.root+ii)->nkids; jj++) + printf(" %d", (st.root+ii)->kids[jj]); + printf("\n\n"); + } +#endif + +/************************************************ +* cast scenario tree into tree +************************************************/ + + struct tree ttree; + cast_sctree2tree(&st, &ttree); + +#if 0 + Nn = ttree.Nn; + printf("\ntree\n"); + for(ii=0; iiidx); + printf("stage = %d\n", (ttree.root+ii)->stage); + printf("real = %d\n", (ttree.root+ii)->real); + printf("idxkid = %d\n", (ttree.root+ii)->idxkid); + printf("dad = %d\n", (ttree.root+ii)->dad); + printf("nkids = %d\n", (ttree.root+ii)->nkids); + printf("kids ="); + for(jj=0; jj<(ttree.root+ii)->nkids; jj++) + printf(" %d", (ttree.root+ii)->kids[jj]); + printf("\n\n"); + } +#endif + +/************************************************ +* tree ocp problem size +************************************************/ + + // node-wise size + int nxt[Nn]; + int nut[Nn]; + int nbxt[Nn]; + int nbut[Nn]; + int nbt[Nn]; + int ngt[Nn]; + int nst[Nn]; + int nsbxt[Nn]; + int nsbut[Nn]; + int nsgt[Nn]; + + for(ii=0; iistage; + nxt[ii] = nx[stage]; + nut[ii] = nu[stage]; + nbxt[ii] = nbx[stage]; + nbut[ii] = nbu[stage]; + nbt[ii] = nb[stage]; + ngt[ii] = ng[stage]; + nst[ii] = ns[stage]; + nsbxt[ii] = nsbx[stage]; + nsbut[ii] = nsbu[stage]; + nsgt[ii] = nsg[stage]; + } + +#if 0 + for(ii=0; iistage-1; + hAt[ii] = hA[stage]; + hBt[ii] = hB[stage]; + hbt[ii] = hb[stage]; + } + + for(ii=0; iistage; + hQt[ii] = hQ[stage]; + hRt[ii] = hR[stage]; + hSt[ii] = hS[stage]; + hqt[ii] = hq[stage]; + hrt[ii] = hr[stage]; + hidxbt[ii] = hidxb[stage]; + hd_lbt[ii] = hd_lb[stage]; + hd_ubt[ii] = hd_ub[stage]; + hCt[ii] = hC[stage]; + hDt[ii] = hD[stage]; + hd_lgt[ii] = hd_lg[stage]; + hd_ugt[ii] = hd_ug[stage]; + hZlt[ii] = hZl[stage]; + hZut[ii] = hZu[stage]; + hzlt[ii] = hzl[stage]; + hzut[ii] = hzu[stage]; + hidxst[ii] = hidxs[stage]; + hd_lst[ii] = hd_ls[stage]; + hd_ust[ii] = hd_us[stage]; + } + +/************************************************ +* create tree ocp qp dim +************************************************/ + + int dim_size = d_tree_ocp_qcqp_dim_memsize(Nn); +#if PRINT + printf("\ndim size = %d\n", dim_size); +#endif + void *dim_mem = malloc(dim_size); + + struct d_tree_ocp_qcqp_dim dim; + d_tree_ocp_qcqp_dim_create(Nn, &dim, dim_mem); + +// d_tree_ocp_qcqp_dim_set_all(&ttree, nxt, nut, nbxt, nbut, ngt, nsbxt, nsbut, nsgt, &dim); + + d_tree_ocp_qcqp_dim_set_tree(&ttree, &dim); + for(ii=0; iim, tmat->n, tmat, 0, 0); + } + for(ii=0; iim, tvec, 0); + } + for(ii=0; iim, tmat->n, tmat, 0, 0); + } + for(ii=0; iim, tvec, 0); + } + for(ii=0; iim, tvec, 0); + } + for(ii=0; iipa+0, 1); + printf("\nt_ub\n"); +// for(ii=0; iipa+nbt[ii]+ngt[ii], 1); + printf("\nt_lg\n"); +// for(ii=0; iipa+nbt[ii], 1); + printf("\nt_ug\n"); +// for(ii=0; iipa+2*nbt[ii]+ngt[ii], 1); + + printf("\nresiduals\n\n"); + printf("\nres_g\n"); +// for(ii=0; iires_g+ii)->pa, 1); + printf("\nres_b\n"); +// for(ii=0; iires_b+ii)->pa, 1); + printf("\nres_m_lb\n"); +// for(ii=0; iires_m+ii)->pa+0, 1); + printf("\nres_m_ub\n"); +// for(ii=0; iires_m+ii)->pa+nbt[ii]+ngt[ii], 1); + printf("\nres_m_lg\n"); +// for(ii=0; iires_m+ii)->pa+nbt[ii], 1); + printf("\nres_m_ug\n"); +// for(ii=0; iires_m+ii)->pa+2*nbt[ii]+ngt[ii], 1); + printf("\nres_d_lb\n"); +// for(ii=0; iires_d+ii)->pa+0, 1); + printf("\nres_d_ub\n"); +// for(ii=0; iires_d+ii)->pa+nbt[ii]+ngt[ii], 1); + printf("\nres_d_lg\n"); +// for(ii=0; iires_d+ii)->pa+nbt[ii], 1); + printf("\nres_d_ug\n"); +// for(ii=0; iires_d+ii)->pa+2*nbt[ii]+ngt[ii], 1); + printf("\nres_mu\n"); +// printf("\n%e\n\n", workspace.res->res_mu); +#endif + +#if PRINT + d_print_mat(1, nx_, x[Nn-1], 1); + double tmp_qc = 0.0; + for(ii=0; ii0) AXPY(nx0, -1.0, pi+(ii-1), 0, res_g+ii, nu0, res_g+ii, nu0); - if(nb0+ng0>0) + if(nb0+ng0+nq0>0) { AXPY(nb0+ng0+nq0, -1.0, lam+ii, 0, lam+ii, nb0+ng0+nq0, tmp_nbgqM+0, 0); AXPY(2*nb0+2*ng0+2*nq0, 1.0, d+ii, 0, t+ii, 0, res_d+ii, 0);