Skip to content

Commit

Permalink
wildcard in STDEP and forward dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Virv12 authored and veluca93 committed Sep 23, 2024
1 parent 80f6e15 commit 772e163
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 15 deletions.
34 changes: 29 additions & 5 deletions task-maker-format/src/ioi/format/italian_yaml/cases_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ where
subtask_name: Option<String>,
/// The mapping from subtask name to subtask id.
st_name_to_id: HashMap<String, SubtaskId>,
/// Mapping from subtask_id to the list of names of dependencies.
st_deps: HashMap<SubtaskId, Vec<String>>,
/// The identifier of the next testcase to process.
testcase_id: TestcaseId,
}
Expand Down Expand Up @@ -162,6 +164,7 @@ where
subtask_id: 0,
subtask_name: None,
st_name_to_id: HashMap::new(),
st_deps: HashMap::new(),
testcase_id: 0,
};

Expand Down Expand Up @@ -192,6 +195,28 @@ where
_ => unreachable!(),
}
}

for entry in &mut cases.result {
if let TaskInputEntry::Subtask(subtask) = entry {
if let Some(deps) = cases.st_deps.get(&subtask.id) {
for dep in deps {
if dep == "*" {
subtask.dependencies = (0..cases.subtask_id).collect();
eprintln!("ASDFASDFQWERQWER {}", cases.subtask_id);
} else {
let dep_id = *cases
.st_name_to_id
.get(dep)
.ok_or_else(|| anyhow!("Unknown subtask name: {}", dep))?;
subtask.dependencies.push(dep_id);
}
}
subtask.dependencies.sort_unstable();
subtask.dependencies.dedup();
}
}
}

Ok(cases)
}

Expand Down Expand Up @@ -555,14 +580,13 @@ where
/// Parse a `:STDEP` command.
fn parse_st_dep(&mut self, line: Pair) -> Result<(), Error> {
for dep in line.into_inner() {
let id = *self
.st_name_to_id
.get(dep.as_str())
.context("Unknown subtask")?;
let Some(TaskInputEntry::Subtask(subtask)) = self.result.last_mut() else {
bail!(":STDEP must immediately follow a #ST: in gen/GEN");
};
subtask.dependencies.push(id);
self.st_deps
.entry(subtask.id)
.or_default()
.push(dep.as_str().to_owned());
}
Ok(())
}
Expand Down
29 changes: 25 additions & 4 deletions task-maker-format/src/ioi/format/italian_yaml/gen_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ where
let mut subtask_id: SubtaskId = 0;
let mut entries = vec![];
let mut st_name_to_id = HashMap::new();
let mut st_deps = HashMap::<SubtaskId, Vec<_>>::new();

let mut default_subtask = Some(SubtaskInfo {
id: 0,
Expand Down Expand Up @@ -145,10 +146,10 @@ where
bail!("#STDEP: must immediately follow a #ST: in gen/GEN");
};
for dependency in line.into_inner() {
let dep_id = *st_name_to_id
.get(dependency.as_str())
.ok_or_else(|| anyhow!("Unknown subtask name: {}", dependency))?;
subtask.dependencies.push(dep_id);
st_deps
.entry(subtask.id)
.or_default()
.push(dependency.as_str().to_owned());
}
}
parser::Rule::copy => {
Expand Down Expand Up @@ -195,6 +196,26 @@ where
_ => unreachable!(),
}
}

for entry in &mut entries {
if let TaskInputEntry::Subtask(subtask) = entry {
if let Some(deps) = st_deps.get(&subtask.id) {
for dep in deps {
if dep == "*" {
subtask.dependencies = (0..subtask_id).collect();
} else {
let dep_id = *st_name_to_id
.get(dep)
.ok_or_else(|| anyhow!("Unknown subtask name: {}", dep))?;
subtask.dependencies.push(dep_id);
}
}
subtask.dependencies.sort_unstable();
subtask.dependencies.dedup();
}
}
}

Ok(entries)
}

Expand Down
8 changes: 4 additions & 4 deletions tests/deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ fn classic(test: TestInterface) {
.must_compile("sol-12.cpp")
.must_compile("sol-012.cpp")
.solution_score("sol-.cpp", vec![0.0, 0.0, 0.0])
.solution_score("sol-0.cpp", vec![30.0, 0.0, 0.0])
.solution_score("sol-1.cpp", vec![0.0, 0.0, 0.0])
.solution_score("sol-0.cpp", vec![0.0, 0.0, 0.0])
.solution_score("sol-1.cpp", vec![0.0, 30.0, 0.0])
.solution_score("sol-2.cpp", vec![0.0, 0.0, 0.0])
.solution_score("sol-01.cpp", vec![30.0, 30.0, 0.0])
.solution_score("sol-02.cpp", vec![30.0, 0.0, 0.0])
.solution_score("sol-12.cpp", vec![0.0, 0.0, 0.0])
.solution_score("sol-02.cpp", vec![0.0, 0.0, 0.0])
.solution_score("sol-12.cpp", vec![0.0, 30.0, 0.0])
.solution_score("sol-012.cpp", vec![30.0, 30.0, 40.0]);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/tasks/deps/gen/GEN
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#ST: 30
#STNAME: st-0
#STDEP: st-1
0

#ST: 30
#STNAME: st-1
#STDEP: st-0
1

#ST: 40
#STNAME: st-2
#STDEP: st-1
#STDEP: *
2

0 comments on commit 772e163

Please sign in to comment.