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

CPM model #49

Merged
merged 10 commits into from
Apr 14, 2023
Merged

CPM model #49

merged 10 commits into from
Apr 14, 2023

Conversation

mandd
Copy link
Collaborator

@mandd mandd commented Mar 24, 2023


Pull Request Description

What issue does this change request address? (Use "#" before the issue to link it, i.e., #42.)

Closes #50

What are the significant changes in functionality due to this change request?

For Change Control Board: Change Request Review

The following review must be completed by an authorized member of the Change Control Board.

  • 1. Review all computer code.
  • 2. If any changes occur to the input syntax, there must be an accompanying change to the user manual.
  • 3. Make sure the Python code and commenting standards are respected (camelBack, etc.) - See on the wiki for details.
  • 4. Regression tests have to complete successfully.
  • 5. If significant functionality is added, there must be tests added to check this. Tests should cover all possible options. Multiple short tests are preferred over one large test.
  • 6. The merge request must reference an issue. If the issue is closed, the issue close checklist shall be done.

@mandd
Copy link
Collaborator Author

mandd commented Mar 24, 2023

@wangcj05: this is the initial development of the model designed to perform critical path calculations for the plant outage optimization project. Do you mind start to take a look at it?
One thing I am not too happy is the fact that for external models (when we need to initialize the class from a given file) we need to pass the initialization input file in the step block rather than doing it directly in the ExternalModel block.

The model is initialized by providing a set of activities and the graph connecting the activities. This is specified in a python class as of now. When a more generic format will be available this class will be expanded

@mandd
Copy link
Collaborator Author

mandd commented Mar 24, 2023

Once the main code is good on your end I will add documentation, fill comments, class documentation, etc

@mandd mandd requested a review from wangcj05 March 24, 2023 22:53
Copy link
Collaborator

@wangcj05 wangcj05 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mandd: I have some comments for you to consider.

Comment on lines 80 to 84
file2open = inputs[0].getFilename()
spec = importlib.util.spec_from_file_location("project", str(file2open))
importedModule = importlib.util.module_from_spec(spec)
sys.modules["project"] = importedModule
spec.loader.exec_module(importedModule)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you may need to add some checks and enhancement for these lines. Here assumes the first file in the 'inputs' is the module file that you want to load, and assumes the module name is "project". If the module name is always "project", I suggest to use self variable to store it, otherwise provide an option for the users to choose which module to load.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, test has been added

self.graph = importedModule.project.graph
return Kwargs

@abc.abstractmethod
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed


self.pert = Pert(self.graph)

end_time = self.pert.info_dict[self.pert.end_activity]['ef']
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

camelBack

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment on lines 95 to 101
inputDict = inputDict['SampledVars']
for input in inputDict.keys():
for act in self.graph.keys():
if act.returnName()==container.mapping[input]:
act.updateDuration(inputDict[input])

self.pert = Pert(self.graph)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems these can be moved to "createNewInput"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct, moved

@@ -0,0 +1,261 @@
# Developed from: https://github.com/nofaralfasi/PERT-CPM-graph
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding this file, one suggestion is to move this file into LOGOS/src/contrib/ folder. If you want to keep this file at the CPM folder and made some modifications, I would suggest to convert it to RAVEN code standards.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file has been edited according to RAVEN code standards

Comment on lines 14 to 25
<ExternalModel name="CPMmodel" subType="LOGOS.BaseCPMmodel">
<variables>A,B,C,D,E,F,G,H,end_time</variables>
<CPtime>end_time</CPtime>
<map var='A'>start</map>
<map var='B'>b</map>
<map var='C'>c</map>
<map var='D'>d</map>
<map var='E'>end</map>
<map var='F'>f</map>
<map var='G'>g</map>
<map var='H'>h</map>
</ExternalModel>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you need to convert the python graphModel construction into XML format

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This structure has been modified, now it is possible to import graph structure of a schedule from xml block

Comment on lines 4 to 24
class project():
start = Activity("start", 10)
b = Activity("b", 20)
c = Activity("c", 5)
d = Activity("d", 10)
f = Activity("f", 15)
g = Activity("g", 5)
h = Activity("h", 15)
end = Activity("end", 20)

activitiesList = [start,b,c,d,f,g,h,end]

graph = {start: [f,b,h],
b : [c],
c : [g,d],
d : [end],
f : [g],
g : [end],
h : [end],
end : []}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do the users need to create the graphModel? or they only need to provide the inputs through input xml, and we can automatically create the graph model?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two methods to import a schedule: the first one is to directly import it in an xml format in the RAVEN input file. The second one is to create a project class which contains all the activities and the graph structure. This second one will be updated once we get specifications of schedule formats coming from software scheduling tools such as P6

@mandd mandd changed the title [WIP] CPM model CPM model Apr 13, 2023
@mandd
Copy link
Collaborator Author

mandd commented Apr 13, 2023

@wangcj05 : I think all the initial set of comments have been addressed

Copy link
Collaborator

@wangcj05 wangcj05 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some general comments for you to consider. @mandd

self.infoDict[activity]["slack"] = self.infoDict[activity]["lf"] - self.infoDict[activity]["ef"]

# add activity to the pert
def addActivity(self, activity, in_connections=[], out_connections=[]):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

camelBack to replace underscore for variables?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@ In, None
@ Out, CPdict, dict, dictionary of activities included in the CP alonf with their corresponding duration
"""
critical_path = self.getCriticalPath()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

camelBack?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

<Sequence>simRun</Sequence>
<batchSize>1</batchSize>
</RunInfo>

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a TestInfo node block

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added


[./CPMmodel_map]
type = 'RavenFramework'
input = 'test_BaseCPMmodel_map.xml'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems you do not add this file yet.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

Copy link
Collaborator

@wangcj05 wangcj05 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the folder in the tests file is not correct, please update it.

tests/tests Outdated
[./CPMmodel]
type = 'RavenFramework'
input = 'test_BaseCPMmodel.xml'
UnorderedCsv = 'MultipleKnapsack/Print_sim_PS.csv'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please update the folder to CPMmodel

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

tests/tests Outdated
[./CPMmodel_map]
type = 'RavenFramework'
input = 'test_BaseCPMmodel_map.xml'
UnorderedCsv = 'MultipleKnapsack/Print_sim_PS_map.csv'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please update the folder to CPMmodel

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@wangcj05
Copy link
Collaborator

Contributions from reviewer only for resolving libraries issues.

@wangcj05
Copy link
Collaborator

PR checklist is good.

@wangcj05 wangcj05 merged commit 4f9470f into devel Apr 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Critical path calculations
2 participants