전체 시계 시간 (벽시계 시간)을 얻으려면 get_time 방법을 사용할 수 있습니다. 로그 출력에 표시된대로 "네트워크 시간"값을 얻으려면 로그 출력을 구문 분석해야합니다.
from __future__ import print_function
import sys
import cplex
class OutputProcessor(object):
"""File-like object that processes CPLEX output."""
def __init__(self):
self.network_time = None
def write(self, line):
if line.find("Network time =") >= 0:
tokens = line.split()
try:
# Expecting the time to be the fourth token. E.g.,
# "Network", "time", "=", "0.48", "sec.", ...
self.network_time = float(tokens[3])
except ValueError:
print("WARNING: Failed to parse network time!")
print(line, end='')
def flush(self):
sys.stdout.flush()
def main():
c = cplex.Cplex()
outproc = OutputProcessor()
# Intercept the results stream with our output processor.
c.set_results_stream(outproc)
# Read in a model file (required command line argument). This is
# purely an example, thus no error handling.
c.read(sys.argv[1])
c.parameters.lpmethod.set(c.parameters.lpmethod.values.network)
start_time = c.get_time()
c.solve()
end_time = c.get_time()
print("Total solve time (sec.):", end_time - start_time)
print("Network time (sec.):", outproc.network_time)
if __name__ == "__main__":
main()
(이 정교한 파서의 모범하는 것은 아닙니다) 당신에게 로그에서 다른 정보를 구문 분석하는 방법의 아이디어를 줄 것이다 다음은이 두 가지를 보여주는 예입니다.
get_dettime에도 관심이있을 수 있습니다. get_time
(위와 동일)과 같은 방식으로 사용할 수 있지만 컴퓨터의 부하에 영향을받지 않습니다.
답변에 따라 코드를 수정 했으므로 감사합니다. 그러나 전체 시간은 네트워크 시간보다 훨씬 길어 보인다 (예 : 1.72 대 0.56 초). 왜 "전체 시간"기간과 "네트워크 시간"기간 동안 무엇을하고 있습니까?) – user12345
Python API는 호출 가능 C 라이브러리를 둘러싼 래퍼입니다. 파이썬 API에서'solve'를 호출하면 호출 할 최적화 루틴 (예 :'CPXXmipopt','CPXXlpopt' 등)을 결정하는 추가 코드가 있으며, 최적화가 완료되면 상태 코드를 확인하여 오류가 발생하지 않았는지 확인하십시오.이 여분의 처리는 아마도 사용자가 보는 차이 일 것입니다. "네트워크 시간"은 호출 가능 C 라이브러리 자체에보고 된 시간입니다. 보고하는 차이가 내가 본 것보다 더 큽니다. 그러나 모델/프로그램에 대해 더 많이 알지 못해서 나는 다른 말을 할 수 없습니다. – rkersh
이제 스케치 아이디어가 있습니다. 감사. – user12345