Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

weighted interventions for optimize #4986

Merged
merged 9 commits into from
Oct 2, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
weighted interventions
Cole Blanchard authored and Cole Blanchard committed Sep 30, 2024
commit 87c45b835c936c9ec2166e76f13a1ea1874ded4a
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<template>
<div class="policy-group">
<div class="form-header">
<label class="mr-auto" tag="h5"> {{ config.intervention?.name ?? `Intervention` }}</label>
<aside>
<label for="active">Optimize</label>
<InputSwitch v-model="knobs.isActive" :disabled="true" @change="emit('update-self', knobs)" />
</aside>
<h6 class="mr-auto">{{ config.intervention?.name ?? `Intervention` }}</h6>
<tera-signal-bars
v-if="!!knobs.relativeImportance"
v-model="knobs.relativeImportance"
@update:model-value="emit('update-self', knobs)"
label="Relative importance"
/>
</div>
<p>
Set the {{ dynamicInterventions[0].type }}&nbsp; <strong>{{ dynamicInterventions[0].appliedTo }}</strong> to
@@ -15,10 +17,9 @@
</div>
</template>
<script setup lang="ts">
import { ref, computed } from 'vue';
import { computed, ref } from 'vue';
import { DynamicIntervention } from '@/types/Types';
import { InterventionPolicyGroupForm } from '@/components/workflow/ops/optimize-ciemss/optimize-ciemss-operation';
import InputSwitch from 'primevue/inputswitch';

const props = defineProps<{
config: InterventionPolicyGroupForm;
@@ -29,7 +30,7 @@ const emit = defineEmits(['update-self']);
const dynamicInterventions = computed<DynamicIntervention[]>(() => props.config.intervention.dynamicInterventions);

const knobs = ref({
isActive: props.config.isActive ?? false
relativeImportance: props.config.relativeImportance
});
</script>
<style>
Original file line number Diff line number Diff line change
@@ -519,11 +519,11 @@ const chartSize = computed(() => drilldownChartSize(outputPanel.value));
const cancelRunId = computed(() => props.node.state.inProgressPostForecastId || props.node.state.inProgressOptimizeId);

const activePolicyGroups = computed(() =>
knobs.value.interventionPolicyGroups.filter((ele) => ele.relativeImportance > 5)
knobs.value.interventionPolicyGroups.filter((ele) => !!ele.relativeImportance)
);

const inactivePolicyGroups = computed(() =>
knobs.value.interventionPolicyGroups.filter((ele) => ele.relativeImportance <= 5)
knobs.value.interventionPolicyGroups.filter((ele) => !ele.relativeImportance)
);
let pyciemssMap: Record<string, string> = {};

@@ -716,11 +716,11 @@ const setInterventionPolicyGroups = (interventionPolicy: InterventionPolicy) =>
knobs.value.interventionPolicyGroups = []; // Reset prior to populating.
if (interventionPolicy.interventions && interventionPolicy.interventions.length > 0) {
interventionPolicy.interventions.forEach((intervention) => {
// const isNotActive = intervention.dynamicInterventions?.length > 0 || intervention.staticInterventions?.length > 1;
const isNotActive = intervention.dynamicInterventions?.length > 0 || intervention.staticInterventions?.length > 1;
const newIntervention = _.cloneDeep(blankInterventionPolicyGroup);
newIntervention.id = interventionPolicy.id;
newIntervention.intervention = intervention;
newIntervention.relativeImportance = 5;
newIntervention.relativeImportance = isNotActive ? 0 : 5;
newIntervention.startTimeGuess = intervention.staticInterventions[0]?.timestep;
newIntervention.initialGuessValue = intervention.staticInterventions[0]?.value;
knobs.value.interventionPolicyGroups.push(newIntervention);
@@ -743,13 +743,15 @@ const runOptimize = async () => {
const listBoundsInterventions: number[][] = [];
const initialGuess: number[] = [];
const objectiveFunctionOption: string[] = [];
const relativeImportance: number[] = [];

activePolicyGroups.value.forEach((ele) => {
// Only allowed to optimize on interventions that arent grouped aka staticInterventions' length is 1
paramNames.push(ele.intervention.staticInterventions[0].appliedTo);
paramValues.push(ele.intervention.staticInterventions[0].value);
startTime.push(ele.intervention.staticInterventions[0].timestep);
objectiveFunctionOption.push(ele.objectiveFunctionOption);
relativeImportance.push(ele.relativeImportance);

if (ele.optimizationType === OptimizationInterventionObjective.startTime) {
initialGuess.push(ele.startTimeGuess);
@@ -779,7 +781,8 @@ const runOptimize = async () => {
startTime,
paramValues,
initialGuess,
objectiveFunctionOption
objectiveFunctionOption,
relativeImportance
};

// These are interventions to be considered but not optimized over.
Original file line number Diff line number Diff line change
@@ -3,12 +3,13 @@
<div class="form-header">
<h6 class="mr-auto">{{ config.intervention?.name ?? `Intervention` }}</h6>
<tera-signal-bars
v-if="!!knobs.relativeImportance"
v-model="knobs.relativeImportance"
@update:model-value="emit('update-self', knobs)"
label="Relative importance"
/>
</div>
<template v-if="true">
<template v-if="!!knobs.relativeImportance">
<section class="input-row">
<p>
Find the
1 change: 1 addition & 0 deletions packages/client/hmi-client/src/types/Types.ts
Original file line number Diff line number Diff line change
@@ -645,6 +645,7 @@ export interface OptimizeInterventions {
startTime?: number[];
objectiveFunctionOption?: string[];
initialGuess?: number[];
relativeImportance?: number[];
}

export interface OptimizeQoi {
Original file line number Diff line number Diff line change
@@ -2,8 +2,10 @@

import com.fasterxml.jackson.annotation.JsonAlias;
import java.util.List;
import java.util.stream.Collectors;
import lombok.Data;
import lombok.experimental.Accessors;
import software.uncharted.terarium.hmiserver.annotations.TSIgnore;
import software.uncharted.terarium.hmiserver.annotations.TSModel;
import software.uncharted.terarium.hmiserver.annotations.TSOptional;

@@ -36,6 +38,10 @@ public class OptimizeInterventions {
@JsonAlias("initial_guess")
private List<Double> initialGuess;

@TSOptional
@JsonAlias("relative_importance")
private List<Double> relativeImportance;

@Override
public String toString() {
return (" { Parameter Names: " + this.paramNames + " start time: " + startTime.toString() + " } ");