-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
NATSUME Hiroaki
committed
Mar 11, 2024
1 parent
5597467
commit 2a8846d
Showing
5 changed files
with
118 additions
and
184 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
using Optuna.Storage; | ||
using Optuna.Study; | ||
using Optuna.Trial; | ||
|
||
using Tunny.Core.Storage; | ||
using Tunny.Core.Util; | ||
|
||
namespace Tunny.Core.Solver | ||
{ | ||
public class Output | ||
{ | ||
private readonly string _storagePath; | ||
|
||
public Output(string storagePath) | ||
{ | ||
_storagePath = storagePath; | ||
} | ||
|
||
public Trial[] GetTargetTrial(int[] targetNumbers, string studyName) | ||
{ | ||
TLog.MethodStart(); | ||
IOptunaStorage storage = StorageHandler.GetStorage(_storagePath); | ||
Study targetStudy = storage.GetAllStudies().FirstOrDefault(s => s.StudyName == studyName); | ||
return targetStudy == null ? Array.Empty<Trial>() : GetTargetTrials(targetNumbers, targetStudy); | ||
} | ||
|
||
private static Trial[] GetTargetTrials(int[] targetNumbers, Study study) | ||
{ | ||
TLog.MethodStart(); | ||
if (targetNumbers[0] == -1) | ||
{ | ||
return study.BestTrials; | ||
} | ||
else if (targetNumbers[0] == -10) | ||
{ | ||
return study.Trials.ToArray(); | ||
} | ||
else | ||
{ | ||
return UseTrialNumber(targetNumbers, study); | ||
} | ||
} | ||
|
||
private static Trial[] UseTrialNumber(IReadOnlyList<int> targetNumbers, Study study) | ||
{ | ||
TLog.MethodStart(); | ||
var trials = new List<Trial>(); | ||
for (int i = 0; i < targetNumbers.Count; i++) | ||
{ | ||
int target = targetNumbers[i]; | ||
Trial trial = study.Trials.FirstOrDefault(t => t.Number == target); | ||
if (trial != null) | ||
{ | ||
trials.Add(trial); | ||
} | ||
} | ||
return trials.ToArray(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.