<template>
    <div class="XFpdding">
                  <div class="numberinput lefttext  dlheight">
                    <el-form-item label="优化算法：" :label-width="formLabelWidth200">
                  <el-select v-model="youhua.algorithm" :suffix-icon="CaretBottom" placeholder="请选择">
                    <el-option v-for="item in yslist" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="续算开关：" :label-width="formLabelWidth200">
                  <el-select v-model="youhua.irestart" :suffix-icon="CaretBottom" placeholder="请选择">
                    <el-option v-for="item in cswitch" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="试验设计方法："  :label-width="formLabelWidth200">
                <!-- <el-input v-model="youhua.ndoe" :step="100" :min="0" :max="1000" controls-position="right" /> -->
                <el-select v-model="youhua.ndoe" :suffix-icon="CaretBottom" placeholder="请选择">
                    <el-option v-for="item in tdlist" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                </el-select>
                </el-form-item>
                <el-form-item label="选择代理模型：" :label-width="formLabelWidth200">
                  <el-select v-model="youhua.surromod" :suffix-icon="CaretBottom" placeholder="请选择" @change="handlesurromodChange">
                    <el-option v-for="item in daililist" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="样本点数："  :label-width="formLabelWidth200">
                  <div style="display: flex;">
                <el-input type="text" style="margin-right: 10px;" v-model="youhua.ns">
                  <!-- <template #prepend>X方向</template> -->
                  <template  #prefix>初始 </template>
                </el-input>
                <el-input type="text" style="margin-right: 10px;" v-model="youhua.nsmax">
                  <template  #prefix>最大</template>
                </el-input>
              </div>
              </el-form-item>
              <el-form-item label="优化进程数："  :label-width="formLabelWidth200">
                <el-input v-model="youhua.proscount" :step="100" :min="0" :max="1000" controls-position="right" />
              </el-form-item>
              <!-- <el-form-item label="屏幕输出等级："  :label-width="formLabelWidth200">
                <el-input v-model="youhua.iout" :step="100" :min="0" :max="1000" controls-position="right" />
                </el-form-item> -->
              <!-- <el-form-item label="低可信度样本点数："  :label-width="formLabelWidth200">
                  <div style="display: flex;">
                <el-input type="text" style="margin-right: 10px;" v-model="youhua.nslf">
                  <template  #prefix>初始 </template>
                </el-input>
                <el-input type="text" style="margin-right: 10px;" v-model="youhua.nsmaxlf">
                  <template  #prefix>最大</template>
                </el-input>
              </div>
              </el-form-item>
              <el-form-item label="各可信度样本点数："  :label-width="formLabelWidth200">
                  <div style="display: flex;">
                <el-input type="text" style="margin-right: 10px;" v-model="youhua.nsmk">
                  <template  #prefix>初始 </template>
                </el-input>
                <el-input type="text" style="margin-right: 10px;" v-model="youhua.nsmaxmk">
                  <template  #prefix>最大</template>
                </el-input>
              </div>
              </el-form-item> -->
              <el-form-item label="最优解收敛性容差："  :label-width="formLabelWidth200">
                <el-input v-model="youhua.xtol" :step="100" :min="0" :max="1000" controls-position="right" />
                </el-form-item>
                <el-form-item label="真实函数约束容差："  :label-width="formLabelWidth200">
                <el-input v-model="youhua.feasibilitytolreal" :step="100" :min="0" :max="1000" controls-position="right" />
                </el-form-item>
                <el-form-item label="代理模型约束容差："  :label-width="formLabelWidth200">
                <el-input v-model="youhua.feasibilitytolsurro" :step="100" :min="0" :max="1000" controls-position="right" />
                </el-form-item>
                
                <el-form-item label="相关函数：" :label-width="formLabelWidth200">
                  <el-select v-model="youhua.corr" :suffix-icon="CaretBottom" placeholder="请选择">
                    <el-option v-for="item in daililist1" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="是否优化超参数：" :label-width="formLabelWidth200">
                  <el-select v-model="youhua.consttheta" :suffix-icon="CaretBottom" placeholder="请选择">
                    <el-option v-for="item in daililist2" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="Kriging模型阶数：" :label-width="formLabelWidth200">
                  <el-select v-model="youhua.porder" :suffix-icon="CaretBottom" placeholder="请选择">
                    <el-option v-for="item in daililist3" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="相关矩阵分解法：" :label-width="formLabelWidth200">
                  <el-select v-model="youhua.dcmp" :suffix-icon="CaretBottom" placeholder="请选择">
                    <el-option v-for="item in daililist4" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="超参数优化算法：" :label-width="formLabelWidth200">
                  <el-select v-model="youhua.paraopt" :suffix-icon="CaretBottom" placeholder="请选择">
                    <el-option v-for="item in daililist5" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="正则化方法：" :label-width="formLabelWidth200">
                  <el-select v-model="youhua.regular" :suffix-icon="CaretBottom" placeholder="请选择">
                    <el-option v-for="item in daililist6" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="加点准则："  :label-width="formLabelWidth200">
                  <!-- <el-input v-model="youhua.infill" :step="100" :min="0" :max="1000" controls-position="right" /> -->
                  <el-select v-model="youhua.infill" :suffix-icon="CaretBottom" placeholder="请选择">
                    <el-option v-for="item in daililist7" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="KB加点数量："  :label-width="formLabelWidth200">
                <el-input v-model="youhua.nparallel" :step="100" :min="0" :max="1000" controls-position="right" />
                </el-form-item>
                <el-form-item label="子优化方法："  :label-width="formLabelWidth200">
                  <!-- <el-input v-model="youhua.iopt" :step="100" :min="0" :max="1000" controls-position="right" /> -->
                  <el-select v-model="youhua.iopt" :suffix-icon="CaretBottom" placeholder="请选择">
                    <el-option v-for="item in daililist8" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="约束处理方法："  :label-width="formLabelWidth200">
                  <el-select v-model="youhua.icstr" :suffix-icon="CaretBottom" placeholder="请选择">
                    <el-option v-for="item in daililist9" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="种群规模："  :label-width="formLabelWidth200">
                <el-input v-model="youhua.ipopsize" :step="100" :min="0" :max="1000" controls-position="right" />
                </el-form-item>
                <el-form-item label="最大进化代数："  :label-width="formLabelWidth200">
                <el-input v-model="youhua.maxgen" :step="100" :min="0" :max="1000" controls-position="right" />
                </el-form-item>
                <el-form-item label="交叉概率："  :label-width="formLabelWidth200">
                <el-input v-model="youhua.pc" :step="100" :min="0" :max="1000" controls-position="right" />
                </el-form-item>
                <el-form-item label="变异概率："  :label-width="formLabelWidth200">
                <el-input v-model="youhua.pm" :step="100" :min="0" :max="1000" controls-position="right" />
                </el-form-item>
            </div>
                </div>
  </template>
<script  setup>
import { ref, onMounted, reactive, provide, nextTick } from "vue";
import { ElMessage, ElButton, ElDialog, ElSelect } from 'element-plus'
import { Edit, CaretBottom } from '@element-plus/icons-vue'
import { request } from "@/utils/request";
let formLabelWidth3=ref(100)
let formLabelWidth200=ref(180)
let youhua = ref({
  algorithm: 'SurroOpt',
  iout: 19,
  proscount:'1',
  irestart: '0',
  ndoe: '0',
  ns: 10,
  nsmax: 100,
  nslf: 20,
  nsmaxlf: 200,
  nsmk: 10,
  nsmaxmk: 100,
  xtol: 1e-8,
  feasibilitytolreal: -1e-6,
  feasibilitytolsurro: -1e-6,
  surromod: 'Kriging',
  corr: '0',
  consttheta: '0',
  porder: '0',
  dcmp: '0',
  paraopt: '1',
  regular: '0',
  infill: '0',
  nparallel: 1,
  iopt: '0',
  icstr: '0',
  ipopsize: 50,
  maxgen: 100,
  pc: 0.9,
  pm: 0.05
})
let pid = ref();
let suid = ref();
let cstnum=ref('');
let yslist = ref([
  { label: 'SurroOpt', value: 'SurroOpt' },
])
let cswitch = ref([
  { label: '是', value: '1' },
  { label: '否', value: '0' },
])

let tdlist = ref([
  {label:'拉丁超立方LHS',value:'0'},
  {label:'均匀设计UD',value:'1'},
  {label:'蒙特卡洛MCD',value:'2'},
])

let nsurro = ref(310)
let n_kriging = ref(1)
let daililist = ref([
  { label: 'Kriging', value: 'Kriging' },
  { label: 'GEK', value: 'GEK' },
  { label: 'Co-Kriging', value: 'Co-Kriging' },
  { label: 'HK', value: 'HK' },
  { label: 'MHK', value: 'MHK' },
])

let daililist1= ref([
  { label: '各向异性高斯指数函数', value: '0' },
  { label: '各向同性高斯指数函数', value: '1' },
  { label: '三次样条函数', value: '2' },

])

let daililist2= ref([
  { label: '不优化', value: '0' },
  { label: '随机初值优化', value: '1' },
  { label: '上一轮建模数据作为初值优化', value: '2' },

])

let daililist3= ref([
  { label: '普通Kriging', value: '0' },
  { label: '泛Kriging', value: '1' },

])

let daililist4= ref([
  { label: 'LU分解', value: '0' },
  { label: 'Cholesky分解', value: '1' },
  { label: '第三方库并行分解', value: '2' },

])

let daililist5= ref([
  { label: 'HookeJeeves', value: '1' },
  { label: 'BFGS', value: '2' },
  { label: '单纯形搜索方法', value: '3' },

])

let daililist6= ref([
  { label: '不进行正则化', value: '0' },
  { label: '常数正则化', value: '1' },
  { label: '优化正则化', value: '2' },

])

let daililist7= ref([
  { label: 'EI+MSP', value: '0' },
  { label: '局部EI', value: '1' },
  { label: 'EI', value: '2' },
  { label: 'MSP', value: '3' },
  { label: 'LCB', value: '4' },
  { label: 'PI', value: '5' },
  { label: 'MSE', value: '6' },
  { label: 'MSP+MSE', value: '7' },
])

let daililist8= ref([
  { label: '当前最优+局部优化', value: '0' },
  { label: '当前最优+局部优化+GA', value: '1' },
])

let daililist9= ref([
  { label: '概率相乘法', value: '0' },
])

const handlesurromodChange = (val) => {
  if(val === 'Kriging') {
    nsurro.value =310
    n_kriging.value = 1
  }else if(val === 'GEK'){
    nsurro.value =310
    n_kriging.value = 2
  }else if(val === 'Co-Kriging'){
    nsurro.value =410
    n_kriging.value = 1
  }else if(val === 'HK'){
    nsurro.value =4
    n_kriging.value = 12
  }else if(val === 'MHK'){
    nsurro.value =4
    n_kriging.value = 12
  }
}

const getDoptimize = (id) => {
  pid.value = id;
  const params = {
    transCode: 'MDO0031',
    pid: pid.value,
  }
  request(params).then((res) => {
    console.log('chushihua')
    if (res.hasOwnProperty('suid')) {

      getDoptimizeAssign(res);

    } else {
    }
  })
  .catch((err) => {
    ElMessage.error(err.returnMsg)
  })
}

const getDoptimizeAssign = (data) => {
  pid.value = data.pid
  suid.value = data.suid;
  youhua.value.algorithm = data.algorithm;
  youhua.value.iout = data.iout;
  youhua.value.irestart = data.irestart;
  youhua.value.ndoe = data.ndoe;
  youhua.value.ns = data.ns;
  youhua.value.nsmax = data.nsmax;
  youhua.value.nslf = data.nslf;
  youhua.value.nsmaxlf = data.nsmaxlf;
  youhua.value.nsmk = data.nsmk;
  youhua.value.nsmaxmk = data.nsmaxmk;
  youhua.value.xtol = data.xtol;
  youhua.value.feasibilitytolreal = data.feasibilitytolreal;
  youhua.value.feasibilitytolsurro = data.feasibilitytolsurro;
  youhua.value.surromod = data.surromod;
  youhua.value.corr = data.corr;
  youhua.value.consttheta = data.consttheta;
  youhua.value.porder = data.porder;
  youhua.value.dcmp = data.dcmp;
  youhua.value.paraopt = data.paraopt;
  youhua.value.regular = data.regular;
  youhua.value.infill = data.infill;
  youhua.value.nparallel = data.nparallel;
  youhua.value.iopt = data.iopt;
  youhua.value.icstr = data.icstr;
  youhua.value.ipopsize = data.ipopsize;
  youhua.value.maxgen = data.maxgen;
  youhua.value.pc = data.pc;
  youhua.value.pm = data.pm;
}

//代理优化器，添加保存
const getaddDsave = () => {
  const params = {
    transCode: 'MDO0032',
    pid: pid.value,
    suid: suid.value,
    nsurro:nsurro.value,
    n_kriging:n_kriging.value,
    algorithm: youhua.value.algorithm,
    iout: youhua.value.iout,
    irestart: youhua.value.irestart,
    ndoe: youhua.value.ndoe,
    ns: youhua.value.ns,
    nsmax: youhua.value.nsmax,
    nslf: youhua.value.nslf,
    nsmaxlf: youhua.value.nsmaxlf,
    nsmk: youhua.value.nsmk,
    nsmaxmk: youhua.value.nsmaxmk,
    xtol: youhua.value.xtol,
    feasibilitytolreal: youhua.value.feasibilitytolreal,
    feasibilitytolsurro: youhua.value.feasibilitytolsurro,
    surromod: youhua.value.surromod,
    corr: youhua.value.corr,
    consttheta: youhua.value.consttheta,
    porder: youhua.value.porder,
    dcmp: youhua.value.dcmp,
    paraopt: youhua.value.paraopt,
    regular: youhua.value.regular,
    infill: youhua.value.infill,
    nparallel: youhua.value.nparallel,
    iopt: youhua.value.iopt,
    icstr: youhua.value.icstr,
    ipopsize: youhua.value.ipopsize,
    maxgen: youhua.value.maxgen,
    pc: youhua.value.pc,
    pm: youhua.value.pm,
    checked:1
  }
  request(params).then((res) => {
    ElMessage({
      message: res.returnMsg,
      type: 'success'
    })
  })
  .catch((err) => {
    ElMessage.error(err.returnMsg)
  })
}
defineExpose({
  getDoptimize,
  getDoptimizeAssign,
  getaddDsave
});
</script>


