forked from StudioInfinity/dyna3
Introduce soft constraints
Use a penalty method as a quick & dirty way to get started.
This commit is contained in:
parent
9e74d4e837
commit
3664ea73b1
3 changed files with 105 additions and 59 deletions
|
@ -402,6 +402,7 @@ pub struct InversiveDistanceRegulator {
|
|||
pub subjects: [Rc<dyn Element>; 2],
|
||||
pub measurement: ReadSignal<f64>,
|
||||
pub set_point: Signal<SpecifiedValue>,
|
||||
pub soft: Signal<bool>,
|
||||
distortion: Option<ReadSignal<f64>>, /* KLUDGE */
|
||||
serial: u64,
|
||||
}
|
||||
|
@ -432,9 +433,10 @@ impl InversiveDistanceRegulator {
|
|||
} else {
|
||||
None
|
||||
};
|
||||
let soft = create_signal(false);
|
||||
let serial = Self::next_serial();
|
||||
|
||||
Self { subjects, measurement, set_point, distortion, serial }
|
||||
Self { subjects, measurement, set_point, soft, distortion, serial }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -464,6 +466,7 @@ impl Serial for InversiveDistanceRegulator {
|
|||
|
||||
impl ProblemPoser for InversiveDistanceRegulator {
|
||||
fn pose(&self, problem: &mut ConstraintProblem) {
|
||||
let soft = self.soft.get_untracked();
|
||||
self.set_point.with_untracked(|set_pt| {
|
||||
if let Some(val) = set_pt.value {
|
||||
let [row, col] = self.subjects.each_ref().map(
|
||||
|
@ -471,7 +474,11 @@ impl ProblemPoser for InversiveDistanceRegulator {
|
|||
"Subjects should be indexed before inversive distance regulator writes problem data"
|
||||
)
|
||||
);
|
||||
problem.gram.push_sym(row, col, val);
|
||||
if soft {
|
||||
problem.soft.push_sym(row, col, val);
|
||||
} else {
|
||||
problem.gram.push_sym(row, col, val);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue